Alexandra
Alexandra

Reputation: 19

Problems with installing Django with Python3

I have installed virtualenv

sudo pip3 install virtualenv

Then created a new virtualenv

virtualenv --python=/usr/bin/python3.5 venv

It returned

Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/alexandra/Documents/online-store/venv/bin/python3.5
Also creating executable in /home/alexandra/Documents/online-store/venv/bin/python
Installing setuptools, pip, wheel...done.

Activated it

source venv/bin/activate

Then installed Django

sudo pip3 install django

It installed there (that is what sudo pip3 install django --upgrade returned)

/usr/local/lib/python3.4/dist-packages

Maybe that's the problem? Because it installed in python3.4 and not python3.5. But how to install Django in python3.5?

In file manage.py there is a path to python3.5 in this virtualenv.

Then I run

python manage.py runserver

It returns an 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'

Can anyone help me?

Upvotes: 0

Views: 1227

Answers (3)

Tasneem Haider
Tasneem Haider

Reputation: 379

Don't do sudo and just use pip for installing all the packages. You have already installed python3 in your virtualenv, so there is no need of using pip3. Just do e.g. pip install django. or for other packages pip install <package_name>

Upvotes: 0

Ton Bon
Ton Bon

Reputation: 46

When using pip to install packages inside the virtual env, do not sudo. It makes packages be installed globally. Simply remove sudo from beginning of the command and it should install it in the venv you are currently working on.

Upvotes: 3

thule
thule

Reputation: 4222

You installed django into a system python 3.4.

When you ran install command first time without sudo, did it complain about permissions? That should have been your clue that it's not the right pip. My guess is pip3 only exists in system python and not your virtualenv. You can use which to find out, but this will work in any case:

venv/bin/pip install django

Upvotes: 0

Related Questions