简体   繁体   English

使用Python3安装Django的问题

[英]Problems with installing Django with Python3

I have installed virtualenv 我已经安装了virtualenv

sudo pip3 install virtualenv

Then created a new virtualenv 然后创建一个新的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 然后安装Django

sudo pip3 install django

It installed there (that is what sudo pip3 install django --upgrade returned) 它安装在那里(这是sudo pip3 install django --upgrade返回的内容)

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

Maybe that's the problem? 也许那是问题所在? Because it installed in python3.4 and not python3.5 . 因为它安装在python3.4而不是python3.5 But how to install Django in python3.5 ? 但是如何在python3.5安装Django

In file manage.py there is a path to python3.5 in this virtualenv. 在文件manage.py中,此virtualenv中有python3.5的路径。

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. 使用pip在虚拟环境中安装软件包时,请勿使用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. 只需从命令开头删除sudo,它应该将其安装在您当前正在使用的venv中。

You installed django into a system python 3.4. 您已将django安装到系统python 3.4中。

When you ran install command first time without sudo, did it complain about permissions? 当您第一次不使用sudo运行install命令时,它是否抱怨权限? That should have been your clue that it's not the right pip . 那应该是你的线索,它不是正确的pip My guess is pip3 only exists in system python and not your virtualenv. 我的猜测是pip3仅存在于系统python中,而不存在于您的virtualenv中。 You can use which to find out, but this will work in any case: 您可以使用which来查找,但是在任何情况下都可以使用:

venv/bin/pip install django

Don't do sudo and just use pip for installing all the packages. 不要做sudo而只是使用pip安装所有软件包。 You have already installed python3 in your virtualenv, so there is no need of using pip3. 您已经在virtualenv中安装了python3,因此无需使用pip3。 Just do eg pip install django . 只是做例如pip install django or for other packages pip install <package_name> 或对于其他软件包pip install <package_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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