Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named django but it is installed

I have two versions of python 2.7 and 3.4 and installed django through pip. it shows in ubuntu terminal:

$ pip freeze Django==1.6.11 $ pip --version pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) $ python Python 2.7.9 (default, Feb  3 2016, 02:50:32)  [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>import django Traceback (most recent call last):   File "<stdin>", line 1, in <module> ImportError: No module named django >>> import sys >>> sys.path ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] >>>  

Any idea??

like image 713
srk Avatar asked Feb 03 '16 18:02

srk


People also ask

How do I fix django error module not found?

To solve the error, install the module by running the pip install Django command. Open your terminal in your project's root directory and install the Django module. Copied! After you install the Django package, you should be able to import it and use it.

How do I know if django is installed?

Simply type python -m django --version or type pip freeze to see all the versions of installed modules including Django.

How do I install django?

Django can be installed easily using pip . In the command prompt, execute the following command: pip install django . This will download and install Django. After the installation has completed, you can verify your Django installation by executing django-admin --version in the command prompt.


1 Answers

Probably, pip installs packages into dist-packages directory, which is not included into PYTHONPATH environment variable. You have a couple of solutions:

  1. Create and configure virtualenv for your project, before using pip. This is the most Pythonic way
  2. Try to install Django using built-in pip module:

    python -m pip install django 

    This command should install packages into site-packages directory.

  3. You may also add dist-packages to your PYTHONPATH. This question should help you: How to globally modify the default PYTHONPATH (sys.path)?
like image 86
awesoon Avatar answered Oct 08 '22 17:10

awesoon