简体   繁体   English

我无法在虚拟环境中访问 django

[英]I am not able to access django inside virtual environment

If I install django on local system, then that django, if I access in virtual environment, will that be accessible, or I have to install django again in VirtualEnvironment?如果我在本地系统上安装django,那么django,如果我在虚拟环境中访问,那是否可以访问,或者我必须在VirtualEnvironment中再次安装django?

you need to install Django in you virtual environment.您需要在虚拟环境中安装 Django。

Example virtualenv (env) on Windows Windows 上的示例 virtualenv (env)

env\Scrips\activate

pip install django

If this is the behaviour you want, you can set the system-site-packages option when you create the virtual environment.如果这是您想要的行为,您可以在创建虚拟环境时设置system-site-packages选项。 See the official documentation .官方文档 This will give the virtual environment access to the system site-packages dir.这将使虚拟环境可以访问系统站点包目录。

Any virtual environment starts out essentially blank, with no packages installed, so you will have to install Django again in the environment.任何虚拟环境一开始基本上都是空白的,没有安装任何软件包,因此您必须在环境中再次安装 Django。

Part of the reasoning for this is because if you install something with pip outside of a virtual environment, there's a chance that another python package or program somewhere might break -- this can be from namespace pollution (installing multiple modules that are imported in the same way but work differently) or having different versions of the software (an update breaks some functionality that something else relies on).部分原因是因为如果您在虚拟环境之外使用 pip 安装某些东西,则有可能另一个 python package 或从某处导入的程序可能会破坏从命名空间中导入的多个模块。方式但工作方式不同)或具有不同版本的软件(更新破坏了其他依赖的某些功能)。 Even if Django itself doesn't break anything, some dependency it has might be able to.即使 Django 本身没有破坏任何东西,它所具有的一些依赖性也可能能够。

Another advantage is that you can always run pip freeze > requirements.txt in your environment to list all installed packages and versions, then pip install -r requirements.txt in another environment.另一个优点是您始终可以在您的环境中运行pip freeze > requirements.txt以列出所有已安装的软件包和版本,然后在另一个环境中pip install -r requirements.txt This makes package import and versioning effortless when you move among development machines or between development and production, and helpful if you'd ever like to roll your own package.这使得 package 导入和版本控制在您在开发机器之间或在开发和生产之间移动时毫不费力,如果您想推出自己的 package,这将很有帮助。

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

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