Mi Po
Mi Po

Reputation: 1213

Is there some way to install a specific Python version when creating a virtual environment

I need to downgrade from python 3.8 to python 3.6 for Tensorflow in a virtual environment

I usually create environment with python -m tempenv /path/to/venv

I noted from this article that you can specify the interpreter when creating a virtual environment

https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

But this requires downloading the interpreter separately

Is there a way to automatically do this in an elegant command or set of commands? So that it would download the needed version of Python (3.6) and the appropriate pip installation in the virtual environment folder?

Upvotes: 1

Views: 236

Answers (1)

Grismar
Grismar

Reputation: 31396

You can only create a virtual environment for the version of Python you're using to create it with.

Having said that, if you need virtual environments for different version of Python (e.g. 3.8.x and 2.7.x), you can simply install both version of Python and use the appropriate one to create new virtual environments with that version of Python in it.

As suggested by @flakes, you can also package managers to further automate the process and avoid having to manually pick and install versions of Python to use - to your preference. Tools like pyenv can then make your life easier switching between versions of Python. However, then we're getting into opinions on what's better or easier - you can make it work with stock Python as suggested.

Upvotes: 3

Related Questions