Installed Django with Pip, but Python couldn't find it

I am trying to install django, but I am not sure how. I think I have django installed, but python python can't seem to use the package.

$ sudo pip install django
Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/site-packages
Cleaning up...

$ python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named django


How to fix it? When I try to start the server I get this error

$ python runserver
Traceback (most recent call last):
  File "", line 8, in <module>
    from import execute_from_command_line
ImportError: No module named



source to share

1 answer

Yours is pip

using a different Python version than yours python

. Check the output of these commands:

pip -V
python -V
python -c 'import sys; print(sys.path)'


There may be multiple versions of Python and Pip on your system. For example, in Bash, if you type python

+ Tabmultiple times, it will show you the available Python binaries on your PATH, for example python2.7

, python3.4

and similarly for pip

+ Tabtoo.

It depends on your system how to properly configure so that both python

and pip

use the same versions.

Your best bet is to use virtualenv . You wouldn't have the same problems as in virtualenv, your Python version and Pip version would be well in sync.

Based on the command output, it pip

uses Python 2.7. One quick fix might be to start Django like this:

python2.7 runserver


Or to run the version pip

corresponding to your default Python version.

This "quick fix" is a dirty fix. It would be better to use virtualenv.



All Articles