How to Create Python Virtual Environment
Background
- Python virtual environments (or “
venv
“s) are used to manage individual project installations of Python. - Python virtual environments are created via the
python
binary.
Steps
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.