How to Create a Python 3 Virtual Environment with virtualenv?

Estimated read time 1 min read

Sure, here are the steps to create a Python 3 virtual environment with virtualenv:

  1. First, ensure that you have virtualenv installed. You can install it via pip by running the following command:
pip install virtualenv
  1. Once virtualenv is installed, navigate to the directory where you want to create the virtual environment.
  2. Create a new virtual environment by running the following command:
virtualenv -p python3 env_name

Here, env_name is the name you want to give to your virtual environment. The -p flag specifies the Python version you want to use, in this case, python3.

  1. Activate the virtual environment by running the following command:
source env_name/bin/activate

This will activate the virtual environment and you should see its name in your terminal prompt.

  1. Now you can install packages and run Python scripts within this virtual environment, without affecting the global Python environment on your system.
  2. When you’re done using the virtual environment, you can deactivate it by running the following command:
deactivate

That’s it! You’ve successfully created a Python 3 virtual environment with virtualenv.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply