The same question has been asked a number of times but I couldn't find the solution.
After I install a package using pip, I am able to import it in python console or python file and it works as expected.
The same package when I try to include in django, it gives import error.
Do I need to modify settings.py file or any requirement that I need to add? I am driving django with the help of virtual env.
Eg:
I am using BeautifulSoup and I am trying to import from bs4 import BeautifulSoup and I am getting error ImportError: No module named 'bs4'
This error only comes in django. I am not able to figure out why this is happening.
Screenshot attached for reference.
1. python console - shows no error
2. django console- import error
I am sorry as it is difficult to read the console but any other thing that I can include which will help me make myself more clear will be appreciated.
You don't show either the code of your site or the command you ran (and the URL you entered, if any) to trigger this issue. There's almost certainly some difference between the Python environment on the command line and that operating in Django.
Are you using virtual environments? If so, dependencies should be separately added to each environment. Were you operating from a different working directory? Python usually has the current directory somewhere in sys.path, so if you changed directories it's possible you made bs4 unavailable that way.
At the interactive Python prompt, try
import bs4
bs4.__file__
That will tell you where bs4 is being imported from, and might therefore give you a clue as to why it's not available to Django.
Related
Well, I am trying to run my django project in new environment, I installed all of my requirements although every package is installed but it is still giving me below mentioned error. I am not sure but I am guessing it is due to version conflict of some modules.
I looked for existing solutions or someone who faced similar situation but no success.
the Random method is located in django/db/models/functions/math.py . change your import statement to this :
from django.db.models.functions.math import Random
I am new to PyCharm (coming from RStudio world). I am just trying to setup a PyCharm project. My first line of code is google library import (Later I intend to write codes for pulling data from BigQuery).
But I am getting an error saying ModuleNotFoundError: No module named 'google' in PyCharm. I tried suggested solutions for a very similar stackoverflow question.
I also tried invalidating cache and restart by doing File >
I can see that the google is installed in the Python interpreter. I am not able to figure out what's the issue. To me looks like it is related to the way we setup environment in PyCharm.
Edit: I checked Project interpreter and Run Configuration interpreter. Both match and still get the same thing.
The library you want to use is not named google, is called google-cloud-bigquery, just install that one.
Look here:
https://cloud.google.com/python/docs/reference/bigquery/latest#windows
I guess you know, but you can install it with pip (like in the above link) or in Pycharm settings (clicking in the + in your third screenshot).
I am following the tutorial here:
http://www.prokopyshen.com/create-custom-zipline-data-bundle
and trying to set up a custom bundle to get price from custom, non US financial assets. I am stuck on the line that says:
Advise zipline of our bundle by registering it via .zipline/extension.py
My extension.py file is located in the .zipline/ directiory and has the following code:
from zipline.data.bundles import register
from zipline.data.bundles.viacsv import viacsv
eqSym = {
"CBA"
}
register(
'CBA.csv', # name this whatever you like
viacsv(eqSym),
)
I don't get what it means to register the bundle via .zipline/extension.py though? I thought it might mean to just run the extension.py file from my terminal via a:
python extenion.py
but that fails and says:
ImportError: No module named viacsv
How do i register this bundle?
I also followed this tutorial and I must confess this part is a little confusing.
First of all, I don't think it's necessary to run:
$ python extension.py
The error message you get probably comes from the fact that Python cannot find the viacsv.py file in sys.path (the places where it looks for modules, etc.). In the tutorial you mentioned, it's not really clear what to do with this file. As far as I am concerned, I just saved the viacsv.py file in my local site-packages directory. As I am on Linux I put it there ~/.local/lib/python2.7/site-packages but it might different for you. You can run the following python script to find out:
import sys
for dr in sys.path:
print dr
Then I just substituted from zipline.data.bundles.viacsv import viacsv with from viacsv import viacsv in extension.py.
I suspect you might be looking for the wrong place for the extension.py file.
For windows machine, the file is under "~\.zipline\extension.py". In my case, it's under "C:\Users\XXXX\.zipline\extension.py".
I had been looking at zipline folder under conda's site-packages folder, and couldn't find it. Then created an extension.py myself wondering why it's not called.
Check a related post here https://www.quantopian.com/posts/zipline-issue-while-creating-custom-bundle-to-bring-yahoo-data.
Same issue here, #Gillu13 pointed me to this solution.
I installed zipline through conda. So zipline is installed in
home/me/anaconda3/envs/krakenex/lib/python3.6/site-packages
in there you will find zipline/data/bundles and you can put viacsv.py in there...
then
from zipline.data.bundles.viacsv import viacsv
works
I'm using netbeans to write a simple python program which I need the requests module for, I've downloaded requests through terminal and it all seems to be fine there but netbeans can't seem to find it.
This is the error that it's throwing up:
import requests
ImportError: No module named requests
I've tried installing the requests library directly into the python folder but the folder won't let me paste anything into it.
There do seem to be answers on the netbeans forums but their server is down so won't let me on their website to my annoyance!
EDIT
I've tried to run python setup.py install as per other answers on the website but had no luck.
EDIT
have tried completely uninstalling python and requests to make sure it wasn't an installation error but still no luck.
This clearly looks like an error of installation of the request module to some other place than where your netbeans expects when running the code.
In your console run
which python
Check if this gives the same path as the one set in your netbeans. You can set your path by adding new platform using Tools > Python Platforms > New:
I would suggest that you learn bit more about sandboxed environments such as virtualenv. This article shows how you can use a virtualenv to install packages and use the same virtualenv for netbeans so that whatever packages you install in the virtualenv will be available in the netbeans for you to use. For this case, it could be requests.
In the end I gave up with requests, as I was using requests to get json data from an API I decided just to go back to the drawing board and start over rather than attempt to fix something that I couldn't work out. I am now using the urllib import and whilst this may not be the most efficient way it works which is the most important thing.
I am trying to use the oauth2app library inside my Django app. I've tried installing the library several ways (easy_install, pip, pip via a requirements file, etc.), and every time it installs just fine. Also every time I can import the library from the Django shell (manage.py shell).
However, when I try to use a view from the library:
(r'^oauth2/token/?$', 'oauth2app.token.handler'),
I get a "No module named oauth2app" import error. I've tried comparing the Python path from the Django debug page to the one from "print sys.path" inside the shell, and the seem to be the same, so I can't for the life of me figure out why one works and the other doesn't.
Can anyone help explain what's going on? I thought the Django shell was an equivalent environment to the Django instance ...
Nevermind, it looks like this was just a case of bad documentation on the library's site; when I changed the urls.py line to:
from oauth2app import token
...
(r'^oauth2/token/?$', token.handler),
it worked, sigh.