Why macOS is pointing to two versions of python 3?

128 Views Asked by At

Good that MacBook now shipped without the dead python2.7.

I have python 3 installed already:

 % python -V
Python 3.9.6

However, I a create an isolated virtual environment, I get Python 3.11 instead.

python -m venv venv

Which means packages installed in the environment go into venv/lib/python3.11.

By this I cannot scripts using:

python my_script_file.py

But

python3 my_script_file.py

Should I completely remove Python 3.9.6? And for any future release, possibly means removing Python 3.11?

What is the pythonic way to handle this?

UPDATE

Apparently, I have 2 versions installed:

% python -V
Python 3.9.6

% python3 -V
Python 3.11.6
2

There are 2 best solutions below

0
On

You can create venv for specific versions right?

like

python3.9 -m venv venv

or

python3.11 -m venv venv
0
On

you need to specify the version using

py -3.11 main.py

to work with that particular version of python if you don't want to uninstall it