Robert's Homepage

How to Create Python Virtual Environment

#python #development #how-to



Create the virtual environment folder via:

# The -m option runs the module as a script
# The first `venv` indicates that we want to create a virtual environment 
# The second `venv` will be the name of the directory which contains the virtual environment. You can name this anything you'd like.
python -m venv venv

Then activate the virtual environment via:

. venv/bin/activate

If everything has been done correctly you should see your prompt change to have a venv prefix:

(venv) yourusername@yourlocalhost: 

You are now ready to use your virtual Python environment.