0

I have a combination of this two questions on stackoverflow: How do I update a Python virtual environment with `venv` (in Python 3.3+) to use a newer version of Python?

python3 : The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program

Currently, I have a virtual enviornment with the interpreter python 3.7.0 in visual studio code and I want to upgrade it to python 3.9.0. So for that I do the following line in the terminal (as mentioned in the first question):

python3.9 -m venv --upgrade

Then I am running in the error of the second question:

PS C:\Users\admin\Documents\Visual Studio 2017\Forecasts> python3.9 -m venv --upgrade python3.9 : The term 'python3.9' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • python3.9 -m venv --upgrade
  • CategoryInfo : ObjectNotFound: (python3.9:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException

what I am doing wrong here?

My python executers are stored in: C:\Users\admin\AppData\Local\Programs\Python\Python39

3
  • Does this answer your question? python3 : The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program Commented Apr 25, 2023 at 13:00
  • When I list the question in my question, then it does not answer my question... Commented Apr 25, 2023 at 13:34
  • Does py -3.9 -m venv --upgrade work for you? It sounds like you didn't add Python3.9 to PATH when you installed it which is why Python3.9 doesn't work. In that case its likely that py -3.9 won't work either, but worth checking. Otherwise you need to update your PATH env variable or reinstall Python 3.9 and check the Add to PATH option. Commented Apr 26, 2023 at 13:40

1 Answer 1

3

I have the following two versions of the python interpreter

Version Location
python3.7.9 E:\Programs\Python\Python37
python3.9.13 E:\Programs\Python\Python39
  1. Create a new TESTENV folder and use vscode to open it as a workspace.

  2. Use the following command in the terminal to create a virtual environment named testenv (python version is 3.7.9)

    E:\Programs\Python\Python37\python.exe -m venv testenv
    

    enter image description here

  3. Use the following command to upgrade the enc virtual environment to pyton999

    E:\Programs\Python\Python39\python.exe -m venv --upgrade E:\Desktop\TESTENV\testenv
    

    enter image description here

So on your machine the command should look like this:

C:\Users\admin\AppData\Local\Programs\Python\Python39\python.exe -m venv --upgrade path\to\your\venv(python3.7.0)

If the python version displayed in the Select Interpreter panel has not changed after executing the command, try restarting vscode or verify it with the code in the picture.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.