What is Virtualenv?
Virtualenv is a tool used for creating isolated Python environments. It allows multiple Python environments/projects to coexist on the same computer with their own dependencies, python versions, and pip versions.
How to install Virtualenv
Using Python’s package manager, pip
or pip3
, virtualenv can be installed with a single command:
|
|
Optionally, you can install it for all users:
|
|
How do I create a new virtualenv environment?
Simply navigate to the project directory and use the virtualenv
cli command with a name for the environment (venv
in this case):
|
|
This creates a new folder named venv
in the project directory.
How do I use/activate a virtualenv (venv) environment?
To activate the virtualized environment, run the following command from the project directory:
On Linux / MacOS:
|
|
On Windows:
|
|
With the isolated environment activated, any pip install packagename
will be contained within the directories of the virtualized environment.
How do I deactivate a virtualenv (venv) environment?
Simply type the following command to deactivate:
|
|