12
  • Ubuntu 15.10
  • Python 3.4.3+
  • Django 1.8.7

When I try to import django in the python3 interpreter, it says ImportError: No module named 'django'. I know Django 1.8.7 installed though, 'cause I can get the version # by doing django-admin --version in the terminal commandline.

When I tried python3 manage.py runserver in a Django project directory, I get this error:

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

So again (as expected), it's not in a path where Python can find it.

I looked in /usr/local/lib/python3.4/dist-packages but it's an empty directory.

I did a whereis django & whereis Django and that simply gives me a line with django: or Django: respectively and no list of paths.

I tried Googling how to find path to Django, but that didn't turn up anything useful.

I found & checked the code of the django-admin file itself, but it doesn't have anything indicating where Django installed to. Oddly, the python file imports the django module and it works, even though the interpreter & Django project files can't see the django module. So it's on the python path but it also isn't?!? I don't know, and I can't find it.

I never had a problem like this with a previous Ubuntu (or any other OS). Has anyone got a clue how I can find where Django installed? Actually, I can't find any of the modules I installed via pip3. I've been trying to figure this out for over an hour now, and I'm very confused & frustrated.

Zamphatta
  • 4,634
  • 8
  • 30
  • 34

2 Answers2

20

Normally pip 3 install on python3 dist-packages

You can always use pip with:

python3 -m pip install package

to check if you are experiencing troubles with another python3 installation

ls /usr/local/lib | grep python

But the easy way to not experiment this headache is by using virtual environments

Zartch
  • 945
  • 10
  • 25
  • Good idea. It shows I have Python3.4 & 3.5 on the system. I had no idea that Ubuntu 15.10 had both 3.4 & 3.5 on it. So I tried starting the python interpreter as `python3.5` instead of just `python3`, and then Django worked! So, thank you! I wouldn't have guessed that Ubuntu was putting on 2 versions of Python 3 & then having the default one be the older version while `pip3` installs to the newer version by default. They hadn't done that before. – Zamphatta Nov 25 '15 at 14:29
4

I think you have installed django outside virtual environment. download virtual environment by

pip install virtualenv
virtualenv your_env

Activate virtual environment.

source your_env/bin/activate

Then, Install django in your virtual environment.

Sapanjeet
  • 66
  • 2
  • This works, thanks. I didn't want to use virtualenv though, I want this to be system wide. – Zamphatta Nov 25 '15 at 14:32
  • 1
    Virtual environments add some slight mental and process overhead in comparison to globally accessible installation, but provide the most flexibility. – Sapanjeet Nov 26 '15 at 04:17