Search code examples
pythonpowershellwindows-10virtualenvwrapperpyenv

How to choose Python version when making a new virtual environment with virtualenvwrapper?


It seems like the current global Python version provided by pyenv-win is automatically being employed, but there seems to be no option or parameter in the commmand mkvirtualenv of virtualenvwrapper to specify a Python version.

E.g. my current global pyenv Python version is this:

PS C:\WINDOWS\system32> pyenv global
3.9.0a4

Last time, I created a virtual environment via PowerShell using the virtualenvwrapper-powershell in particular with this command:

MkVirtualEnv -Name MyEnv -Python ThePythonDistDir

As you can see, the ThePythonDistDir needs to be passed by the user and thus refers to an already existing Python-version installed in some directory; in my case via pyenv-win.

So, is there a way to choose directly with virtualenvwrapper a new Python version, which would then be downloaded and installed automatically?


Solution

  • Thanks to all the info @phd has given me in the comments, the alternatives are:

    1. Option parameter to the mkvirtualenv - function hidden in virtualenv options, e.g.: mkvirtualenv --python C:\Python27\python.exe

    2. Globally activate a Python version of desired, e.g. via pyenv global 3.9.0, before running the command mkvirtualenv to create the new venv