python-3.xpython-venv

how to create a venv with a different python version


I have different venvs in my machine in which I have python 3.10.

Now for a specific project, I realised that python 3.10 is not suitable as some libraries are still not compatible. Therefore when creating a new venv for a new project, I would like to downgrade python, say to 3.8, only for this specific venv.

How can I do that? What should I type onto the terminal to do this?

PS: I use VS and its terminal to create venv


Solution

  • You can have multiple python versions installed at the same time and you can create virtual environments with the needed version. Make sure you have installed the python version you need and then specify its location when you create the virtual environment:

    virtualenv -p <path-to-new-python-installation> <new-venv-name>
    

    Example:

    virtualenv -p  C:\Users\ssharma\AppData\Local\Programs\Python\Python38\python.exe venv38
    

    This will create a virtual environment called venv38 with Python 3.8.