1

I'm working on a big project that needs to be ported from python2.7 to python3.7. For developing, I rely on virtual envs.

For the 2.7v, I'm using a virtual environment created with the virtualenv module and it's packages virtualenvwrapper, and virtualenvwrapper-win.

For the 3.7v, I tried to create an env by using the same packages, this time I installed them to the python3.7 directory. I managed to set up the python3.7 with its own environmental variable, naming it python3.exe so I could chose, where to install additional python packages.

i.e. pip install virtualenv - to install Virtualenv in the python2.7 directory, but

python3 -m pip install virtualenv - to install it into the python3.7 directory

C:\Users\user1>pip freeze
...
stevedore==1.30.1
virtualenv==16.4.3
virtualenv-clone==0.5.1
virtualenvwrapper==4.8.4
virtualenvwrapper-win==1.2.5

vs.

C:\Users\user1>python3 -m pip freeze
...
stevedore==1.31.0
virtualenv==16.7.5
virtualenv-clone==0.5.3
virtualenvwrapper==4.8.4
virtualenvwrapper-win==1.2.5

So far so good.

When I want to create a virtual env named envTest with python3.7, here's the command I use:

mkvirtualenv python3 envTest

To avoid any further misidentification, I renamed the new python executable in the local env's folder to python0.exe.

Now, I can check the paths and versions of all three available python sources (python.exe=python2.7 , python3.exe=python3.7, and python0.exe= python executable from virtual env).

BUT, here is what I get:

(envTest) C:\Users\user1\projects\env_testing>whereis python
C:\Python27\python.exe

(envTest) C:\Users\user1\projects\env_testing>whereis python3
C:\Users\user1\AppData\Local\Programs\Python\Python37\python3.exe

(envTest) C:\Users\user1\projects\env_testing>whereis python0
C:\Users\user1\Envs\envTest\Scripts\python0.exe

(envTest) C:\Users\user1\projects\env_testing>python --version
Python 2.7.16

(envTest) C:\Users\user1\projects\env_testing>python3 --version
Python 3.7.4

(envTest) C:\Users\user1\projects\env_testing>python0 --version
Python 2.7.16

(envTest) C:\Users\user1\projects\env_testing>

It looks to me, like I didn't get the right virtualenvwrapper when creating the envTest env, and thereby indirectly called the wrong python version.

How could I fix this?

I also tried to simply try the python3.x built-in venv, but using it, I get an Error message:

C:\Users\user1\projects>python3 -m venv ./venv_Test venvEnv
Error: [WinError 2] The system cannot find the file specified

even though it created the following directories, although without python executable

C:\Users\user1\projects\venv_Test>dir
...
30.01.2020  14:41    <DIR>          .
30.01.2020  14:41    <DIR>          ..
30.01.2020  14:41    <DIR>          Include
30.01.2020  14:41    <DIR>          Lib
30.01.2020  14:41               117 pyvenv.cfg
30.01.2020  14:41    <DIR>          Scripts
...

1 Answer 1

1

I solved the problem with the following steps:

  1. I read about the Python Launcher for Windows py.exe.

  2. I had to rename my Python3.7 executable from python3.exe back to python.exe in order to make it executable with py.exe.

  3. For creating a virtual env with virtualenv I used py.exe with the following command:

mkvirtualenv envTest2 -p C:\Users\user1\AppData\Local\Programs\Python\Python37\python.exe

everything checks out, now:

(envTest2) C:\Users\user1\projects\env_testing>whereis python
C:\Users\user1\Envs\nanopy3\Scripts\python.exe

(envTest2) C:\Users\user1\projects\env_testing>python --version
Python 3.7.4
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.