My old computer died. Here's my chance to start fresh using virtual environments.
I started with a fresh install of python 2.7.18 and 3.7.9 on a new Windows 10 computer. (It doesn’t matter if I install python 3.7.9 for all users or just one account. I’ve tried both with the same results.)
I want to set up venv for python 3. (I tried with venv and virtualenv with the same results.)
I go to my project directory and type:
py -3.7 -m pip list
>Package Version
>---------- -------
>pip 20.2.3
>setuptools 47.1.0
I create a virtual environment for my project.
py -3.7 -m venv venv
and activate the virtual environment.
venv\Scripts\activate.bat
The prompt changes to show I’m using the virtual environment.
py -3.7 -m pip list
>Package Version
>---------- -------
>pip 20.2.3
>setuptools 47.1.0
Now I install a daily build of wxPython to the virtual environment.
py -3.7 -m pip install "d:\((username))\Downloads\Python\python3.7-64\wxPython-4.1.1a1.dev4959+47c4a913-cp37-cp37m-win_amd64.whl"
This successfully installs wxPython. The prompt shows I’m still in virtual environment. I confirm the installation.
py -3.7 -m pip list
>Package Version
>---------- ------------------------
>numpy 1.19.2
>Pillow 7.2.0
>pip 20.2.3
>setuptools 47.1.0
>six 1.15.0
>wxPython 4.1.1a1.dev4959+47c4a913
This is just what I expect. I now deactivate the virtual environment.
deactivate
The prompt changes, so I am no longer using the virtual environment. But
py -3.7 -m pip list
>Package Version
>---------- ------------------------
>numpy 1.19.2
>Pillow 7.2.0
>pip 20.2.3
>setuptools 47.1.0
>six 1.15.0
>wxPython 4.1.1a1.dev4959+47c4a913
That's not what I expected. I thought wxPython (along with numpy, Pillow, and six) would no longer show up. Looking at where files are added, I see that the pip changes are made to C:\Users((username))\AppData\Local\Programs\Python\Python37\Lib\site-packages, not to D:((username))\Documents\Programming\Python((projectname))\venv\Lib\site-packages, which is what I expected.
And when I start Python 3.7.9 again, I still have all the packages installed without loading my virtual environment. So the whole virtual environment concept is totally ignored.
Can anybody help me understand what I've done wrong, and more importantly, what I need to do differently?
Thanks
Thanks for the replies. It turns out that py launcher and virtual environments are incompatible. Here's what I've done.
I've set up batch files so that I can select which python (2.7 or 3.7) I'm using. The batch files set the Windows PATH to point to the correct Python installation. (I haven't had to set any other environment variables yet, but will edit this if I find I need to.)
I then use "python" rather than "py -3.7" when using python 3.7 to set up and to access my virtual environments.
So when I'm in my virtual environment,
gives me different results than
So hello setting paths, goodbye py launcher. Now virtual environments work like I expected.