简体   繁体   English

ImportError:在virtualenv中没有名为“ django”的模块

[英]ImportError: No module named 'django' when in virtualenv

new to python and django and getting the ImportError when I run python manage.py runserver. python和django的新功能,当我运行python manage.py runserver时得到ImportError。

I figured the problem was that django was not installed in the site_packages of the python version running in the virtualenv. 我发现问题是在virtualenv中运行的python版本的site_packages中未安装django。 I ran the command under sudo "sudo python manage.py runserver" and it works. 我在sudo“ sudo python manage.py runserver”下运行了命令,它可以正常工作。 So all is good. 所以一切都很好。

Can someone explain to a noob what I did wrong in installing django or setting up the virtualenv. 有人可以向菜鸟解释在安装django或设置virtualenv时我做错了什么。

You have to install Django inside the virtualenv. 您必须在virtualenv中安装Django。

sudo command will give you the global package so I guess django already installed in global. sudo命令将为您提供全局软件包,因此我想django已安装在global中。

Activate virtualenv then pip install django will resolve your issue. 激活virtualenv,然后pip install django将解决您的问题。

Did you remember to activate the virtual environment. 您还记得激活虚拟环境吗? Virtual environments never use the sudo command because nothing is being installed in the machines local library. 虚拟环境从不使用sudo命令,因为计算机本地库中未安装任何内容。 To activate the virtual environment you open up terminal and type source /virtualenv/bin/activate. 要激活虚拟环境,请打开终端,然后键入source / virtualenv / bin / activate。

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

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