I am using a Virtualenv on my Django install and have loaded in Pycrypto using
pip install pycrypto
after sourcing my environment.
When I try to import Crypto into my model, I get an import error, however if load the shell using
manage.py shell
it does load in, with out an issue.
I am pretty sure that django is running from the virtualenv as is it running 1.3.1 which more current than what is installed on the path and I have installed South via pip which is working.
I have also tried to install Pycrypto using
setup.py install
Any thoughts on how I fix/debug this?
Thanks
Edit:
I am relatively new to Django and Python so it could be something simple
Edit 2:
Hey Issac,
Is there any way that you can find all the modules getting loaded in?
I don't understand why it wouldn't work in browser but would work in the interactive shell? I am not saying that it can't, i just don't know if/how that could happen.
The import error as requested:
ImportError at /
No module named Crypto
Request Method: GET
Request URL: http://*/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
No module named Crypto
Exception Location: /home/*************/project/app/models.py in <module>, line 1
Python Executable: /home/*************/env/bin/python
Python Version: 2.6.6
Python Path:
['/usr/local/dh/passenger/lib/phusion_passenger/wsgi',
'/home/*************/env/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg',
'/home/*************/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg',
'/home/*************/env/src/django-debug-toolbar',
'/home/*************/env/lib/python2.6',
'/home/*************/env/lib/python2.6/plat-linux2',
'/home/*************/env/lib/python2.6/lib-tk',
'/home/*************/env/lib/python2.6/lib-old',
'/home/*************/env/lib/python2.6/lib-dynload',
'/usr/lib/python2.6',
'/usr/lib64/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-tk',
'/home/*************/env/lib/python2.6/site-packages',
'/home/*************',
'/home/*************/project']
Server time: Tue, 3 Jan 2012 20:08:19 +1100
Just before the line which causes the import error insert this code:
import sys
assert False, sys.path
Compare both results.
In the shell (where you can import the module). You can do this:
import Crypto
assert False, Crypto.__file__
Is the directory of this result in sys.path of your webserver?
Related
I get the error module not found when trying to import requests in Django.
I cannot get python module requests to work in Django. I have installed the module using pip in python and can import in the python terminal.
ModuleNotFoundError: No module named 'requests'
if I run the commands in python shell:
>>> import requests
>>> test = requests.get(url="http://192.168.9.186:2480/connect/test")
i get a htto 204 response but in django I just get the module error
Thanks #H4kor my naive understanding of Python and Django I assumed they were using the same code library. After I ran:
pip install requests
The code ran through and resolved the error. Appreciate the help for this novice.
I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.
I was using Django 1.8 and I wanted to upgrade to the latest version (1.11.6). When I did that I got this error message when trying to run the development server:
from django.utils.deprecation import RemovedInDjango19Warning
ImportError: cannot import name RemovedInDjango19Warning
I can uninstall django and run pip install django=1.9 but I want to keep the latest version. Any tip of how to solve that? Thanks!
PS: I'm running python 2.7.13
The problem was actually in python 2.7.
Reinstalling Python 2.7 solved the issue.
How did I came up with the solution?
I tried python3 manage.py runserver instead of python manage.py runserver and the server worked (but with problems of course since I was using print x instead of print(x) So I knew there was something up with python not django.
I am running a django app on Windows server 2008 R2(64 bit). The same app works fine on my other system which has windows 7 64 bit. I am actually trying to move the app to the other machine. I am using Python 2.7 and django 1.4. The manage.py runserver works fine and is able to start the server.
0 errors found
Django version 1.4, using settings 'checkmeout.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[11/Aug/2016 05:22:09] "GET /admin/ HTTP/1.1" 500 115256
While trying to access the admin page or any other url from http://127.0.0.1/8000,I am getting the following error.
ImportError at /admin/
No module named apps
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.4
Exception Type: ImportError
Exception Value:
No module named apps
Exception Location: C:\Python27\lib\site- packages\django_extensions\admin\__init__.py in <module>, line 10
Python Executable: C:\Python27\python.exe
Python Version: 2.7.5
Python Path:
['C:\\HardwareReservation\\checkmeout2',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:/SoftwareServices/checkmeout']
The output of pip freeze (on the system where it does not work) is put below in case that helps.
amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
celery==3.1.23
Django==1.4
django-apps==0.1.0
django-celery==3.1.17
django-extensions==1.7.1
djangorestframework==3.2.0
kombu==3.0.35
MySQL-python==1.2.4
pytz==2016.6.1
six==1.10.0
South==1.0.2
web.py==0.37
The pip freeze on the system where it works is below :
amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
celery==3.1.23
Django==1.4
django-celery==3.1.17
django-extensions==1.6.7
kombu==3.0.35
MySQL-python==1.2.5
pysphere==0.1.7
python-ldap==2.4.25
pytz==2016.4
six==1.10.0
South==1.0.2
virtualenv==15.0.2
I ran into a similar problem. Try installing the older version of django-extensions that worked:
pip install django-extensions=="1.6.7"
Hi I am getting the error below when going to the website url on ubuntu server 14.10 running apache 2 with mod_wsgi and python on django.
My django application uses python 3.4 but it seems to be defaulting to python 2.7, I am unable to import image from PIL and AES from pycrypto.
ImportError at / cannot import name _imaging Request
Method: GET Request URL: Django Version: 1.7.3
Exception Type: ImportError Exception Value: cannot import
name _imaging Exception
Location: /usr/local/lib/python3.4/dist-packages/PIL/Image.py in
, line 63 Python Executable: /usr/bin/python Python
Version: 2.7.6 Python Path: ['/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages', '/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages']
I believe that mod_wsgi is compiled against a specific version of python, so you need a py3.4 version of mod_wsgi. You may be able to get one from your os's package repository or you can build one without too much drama. From memory you'll need gcc and python-dev packages (python3-dev?) to build.
OK, quick google, for ubuntu 14.10: sudo apt-get install libapache2-mod-wsgi-py3 should install a py3 version of mod_wsgi (will probably want to remove the existing py2 version).
Adding a shebang line won't do any good as the python interpreter is already loaded before the wsgi.py script is read.
From what I see here your application is using py2 interpreter with py3 compiled modules, which is no-go.
One simple possible solution that comes me in mind is to add or change first line of manage.py to #!/usr/bin/python3. This will tell script to be interpreted with py3.
Next on guess list would be misconfiguration in *.wsgi file or apache config, whichever you are using.
Thanks guys,
I actually fixed the issue myself this morning by running the make install of mod_wsgi with .configure pointing to python3.4.
I think you were right Adam.