How to Switch Between Python Versions on VS Code Terminal

I was trying to install pytorch and was getting the error as in this post

C:\Users\Ben>pip install torch

ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch

I created the virtual environment using py commands. First list your environment using py command given below.

py -0

I had three versions as shown below

 -V:3.12 *        Python 3.12 (64-bit)

-V:3.11 Python 3.11 (64-bit)
-V:3.10 Python 3.10 (64-bit)

Creating Virtual Environment

Then I created virtual environment for Python 3.11 version using following command.

py -3.11 -m venv ai311

ai311 is my virtual environment name. You can choose your environment name.

Activate Environment

Activate the ai311 environment using following command.

.\ai311\Scripts\activate

Check the version using the following command.

python --version

You will see Python 3.11.x

I could then go ahead and install pytorch. Happy coding.