简体   繁体   中英

python3 venv sees packages from python2

I have Python2.7 and Python 3.7 installed side by side. 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.

When I run python -v in the venv I get 3.7, but when I run flask --version I get:

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. But other things break for me. Is there a way to remove Python27 from the path only when activating the virtual env?

EDIT: This is my 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?

Thanks

The whole idea of a virtual environment is that it is a fresh work environment without any pip libraries installed.
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.
2. Repeat the same from 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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