'Visual studio Code not running Python 3

My computer: MacBook Air M1 Running 11.6.3 Memory 8GB

Things I have tried:

  1. Reinstalled Visual studio code

  2. Use pyenv to install Python 3.10.2

  3. pyenv install 3.10

  4. pyenv global 3.10

  5. Had brew reinstall pyenv 2.2.4

  6. Also tried command python3.10 -V just reverts back to python 2.7 right away.

Every time I open Visual studio code, to get python 3 to run I must run the two commands below. Just wondering if there is a more permanent solution to the problem. Once I run the command, I have no problems, and can run python programs normally, but the next time I restart Visual studio code, the same issue comes back. Any solution would be helpful... many thanks!!

alias python="python3" # to use python3 rather than python2.7

alias idle="idle3" # to use python3 idle rather than 2.7



Solution 1:[1]

Simply running the command python3.10 fixed the problem. I was just using python nameoffile.py to run a program. Not aware that VSC was defaulting to Python 2.7 built into the Mac OS.

python3.10 nameoffile.py

Many Thanks everyone

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bradley Pretzer