简体   繁体   English

venv从python2看到软件包

[英]python3 venv sees packages from python2

I have Python2.7 and Python 3.7 installed side by side. 我并排安装了Python2.7和Python 3.7。 When I create a venv in a Python3.7 project, it "sees" the global packages of Python2.7 ie: I'm running a flask project without installing anything (even flask) and it works, because all the required packages are present in the 2.7 installation. 当我在Python3.7项目中创建venv时,它“看到”了Python2.7的全局软件包,即:我正在运行flask项目而不安装任何东西(甚至flask),并且它可以工作,因为存在所有必需的软件包在2.7安装中。

When I run python -v in the venv I get 3.7, but when I run flask --version I get: 当我在venv中运行python -v时,我得到3.7,但是当我运行flask --version我得到:

Flask 0.12.2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)]

EDIT: I've found that I have c:\\Python27 in my PATH, if I remove it all works as expected. 编辑:我发现我的PATH中有c:\\Python27 ,如果我将其删除,则所有工作都将按预期进行。 But other things break for me. 但是其他事情对我来说却是坏事。 Is there a way to remove Python27 from the path only when activating the virtual env? 是否只有在激活虚拟环境时才可以从路径中删除Python27?

EDIT: This is my pyvenv.cfg : 编辑:这是我的pyvenv.cfg

home = c:\Python37
include-system-site-packages = false
version = 3.7.2

How do I completely separate the venv from the rest of my local environment? 如何将venv与其他本地环境完全分开?

Thanks 谢谢

The whole idea of a virtual environment is that it is a fresh work environment without any pip libraries installed. 虚拟环境的整个想法是,它是一个全新的工作环境,没有安装任何pip库。
If you activate your virtual environment, you should not see any installed packages unless you explicitly install them. 如果激活虚拟环境,则除非明确安装它们,否则不应看到任何已安装的软件包。
Few suggestions: 几点建议:
1. Try uninstalling flask from python2.7 global package and see what happens. 1.尝试从python2.7全局软件包中卸载flask,然后查看会发生什么。
2. Repeat the same from python3.7. 2.从python3.7重复同样的操作。
3. Make sure you have different aliases for python2.7 and python3.7, and are using the correct alias to create the vend . 3.确保您对python2.7和python3.7使用不同的别名,并使用正确的别名创建vend。

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

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