Search code examples
djangovirtualenvpycrypto

Django not loading Module Pycrypto into model, will load into shell


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

Solution

  • 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?