Virtual environment (venv) gives a different python version from interpreter

Question:

In VS Code (Windows), my python interpreter points to version 3.11.
python -V in terminal gives me Python 3.11.0

I create a virtual environment with python3 -m venv virtual called virtual, and activate it with .virtualScriptsactivate.
Now in my environment, checking python -V gives me Python 3.9.13 instead.

How do I get venv to create a Python 3.11 environment?

Asked By: Desmond

||

Answers:

In the view tab above click on Comand palette> python interpreter from there you can select python 3.11, otherwise you can add it by clicking on enter interpreter path and then select the path where python 3.11 is located at

Answered By: Reactord

You are creating virtual environment with python3 but checking version with just python. I want you to check if python and python3 are pointing same python executable file before creating virtual environment.

May be try creating virtual environment using just python, since its version is 3.11.0.

$ python -m venv virtual

Or you can create virtual environment with specifing the path of your python 3.11 executable file.

$ C:/path/to/your/python3-11-execuatable/python.exe -m venv virtual
Answered By: Althaf