简体   繁体   English

对 python django 中的虚拟环境感到困惑

[英]Confused with virtual environments in python django

I have my Django project folder and inside that i have my virtualenv folder我有我的 Django 项目文件夹,里面有我的virtualenv文件夹

I have few questions我有几个问题

  1. I have packages already installed in main installation and as well in virtual env.我已经在主安装和虚拟环境中安装了软件包。 Dont those packages mix with each other.不要这些包相互混合。 I mean if i have old version in main installation and new version in virtual env how does the system knows which one to choose我的意思是如果我在主安装中有旧版本而在虚拟环境中有新版本系统如何知道选择哪个

  2. Suppose i move my project folder to new computer than can i use same virtual env folder because it was in the same app directory or i have to start all over again假设我将我的项目文件夹移动到新计算机而不是我可以使用相同的虚拟 env 文件夹,因为它在同一个应用程序目录中,或者我必须重新开始

  3. How will i know that pip install package to virtual env or main installation我怎么知道 pip 安装包到虚拟环境或主安装

  1. Unless you created the virtualenv with --system-site-packages, packages don't mix at all.除非您使用 --system-site-packages 创建 virtualenv,否则包根本不会混合。 If they did, Virtualenv has priority.如果他们这样做了,Virtualenv 有优先权。

  2. If the path doesn't change, there are chances that you can reuse it.如果路径没有改变,您就有机会重用它。 You could make a virtualenv --relocatable if the path changes.如果路径发生变化,您可以创建一个 virtualenv --relocatable But you should make a requirements file and be able to regenerate a fresh virtualenv in one pip -r req.txt command.但是你应该制作一个需求文件,并且能够在一个pip -r req.txt命令中重新生成一个新的 virtualenv。

  3. If a virtualenv is activated, pip will install in the virtualenv, it has priority.如果 virtualenv 被激活,pip 将安装在 virtualenv 中,它具有优先权。

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

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