W3docs

Use different Python version with virtualenv

To use a different Python version with virtualenv, follow these steps:

To use a different Python version with virtualenv, follow these steps:

  1. Install the desired Python version. If it is not already installed on your system, you can download it from the official Python website (https://www.python.org/) or use a package manager like conda or your OS package manager.
  2. Install virtualenv. Run the following command to install the package:
pip install virtualenv
  1. Create a virtual environment. To create a virtual environment, run the following command in your terminal:
virtualenv myenv -p python3.8

Replace python3.8 with the path to your desired Python executable. 4. Activate the virtual environment. To activate the virtual environment, run the following command:

source myenv/bin/activate

On Windows, use:

myenv\Scripts\activate
  1. Check the Python version. To check the Python version in your virtual environment, run the following command:
python -V

This will print the version of Python being used in your virtual environment. 6. Deactivate the virtual environment. To deactivate the virtual environment, run the following command:

deactivate

Note: Modern Python versions include the built-in venv module, which is the recommended standard library alternative to virtualenv.