简体   繁体   中英

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?

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.

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

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 eg pip install django . or for other packages pip install <package_name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM