Rocky Linux 8.6: Why can't the system find the Python installation?

I have Python 3.6 and Python 3.10 installed in my server. I have five virtual servers and I would like to create a standalone 3.10 environment for one of them (I wouldn’t mind installing 3.11), but if I write

python -m venv miapi-env

the system returns me

-bash: python: command not found

Can someone help me? Thanks in advance.

if I write

whereis python

I get the answer:

python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/bin/python3.10 /usr/local/bin/python3.10-config /usr/local/lib/python3.10 /usr/include/python3.6m /usr/share/man/man1/python.1.gz

I previously ran

sudo update-alternatives --config python3

with the following result:

There are 2 programs which provide 'python3'.

  Selection    Command
-----------------------------------------------
*  1           /usr/bin/python3.6
 + 2           /usr/bin/python3.10

Enter to keep the current selection[+], or type selection number: 2

(I selected number 2.)

Create a Virtual Environment:

  • Use the python3.10 command explicitly to specify the desired Python version:

Bash

python3.10 -m venv miapi-env
    • This will create a virtual environment named miapi-env using Python 3.10.
  • Activate the Virtual Environment:
  • Navigate to the created environment directory:
    Bash
cd miapi-env

Activate the environment:

Bash

source bin/activate
    • This will set the environment variables to use the Python 3.10 installation within the virtual environment.

Additional Considerations:

  • Updating Python: If you prefer to use Python 3.11, you can install it and then follow the same steps to create a virtual environment using python3.11 .
  • Managing Virtual Environments: Consider using a tool like virtualenvwrapper or conda to manage your virtual environments more efficiently.

Example:
Bash

# Create a virtual environment using Python 3.10
python3.10 -m venv miapi-env

# Activate the virtual environment
cd miapi-env
source bin/activate

# Install required packages
pip install -r requirements.txt

By following these steps, you should be able to successfully create a standalone Python 3.10 environment and use it for your development projects.