0

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 i.e: 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

MeLight
  • 5,454
  • 4
  • 43
  • 67

1 Answers1

0

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 .

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
  • Thanks for prompt reply, I'm not familiar with the alias concept, can you point me to some docs? Also, I uninstalled flask from Python2.7, and it's now not recognized in both environments, as expected – MeLight Feb 10 '19 at 13:39
  • I mean to say that you should check if you are using the correct version python binary to create the venv. e.g `$ which python /usr/bin/python $ which python3.6 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6` – Devesh Kumar Singh Feb 10 '19 at 13:42
  • Yes, I'm using Python3.7 to create venv. – MeLight Feb 10 '19 at 13:45
  • Then you should not see flask in the venv – Devesh Kumar Singh Feb 10 '19 at 13:46
  • You can look up aliasing here e.g. https://stackoverflow.com/questions/35435517/creating-an-alias-for-python3 also did installing flask on your 3.7 venv resolve the issue @MeLight ? – Devesh Kumar Singh May 25 '19 at 17:44