|
# Python Virtual Environments
|
|
# Python Virtual Environments
|
|
|
|
|
|
TO DO |
|
Python Virtual Environments (or virtualenvs) are a mechanism to install Python packages not available system-wide, in user directories. They also allow you to have a different Python environment for each project, which is useful for example when you need different versions of the same package for different projects.
|
|
\ No newline at end of file |
|
|
|
|
|
A complete guide on virtualenvs can be found [here](https://thepythonguru.com/python-virtualenv-guide/). Next, we report only some basic commands.
|
|
|
|
|
|
|
|
|
|
|
|
Create a Python3 virtualenv in the folder `./pyenv` (done once per project):
|
|
|
|
```
|
|
|
|
python3 -m venv --system-site-packages ./pyenv
|
|
|
|
```
|
|
|
|
|
|
|
|
Activate the virtualenv (done for each new shell from where you want to execute code belonging to the project):
|
|
|
|
```
|
|
|
|
source ./pyenv/bin/activate
|
|
|
|
```
|
|
|
|
|
|
|
|
Deactivate the virtualenv (the `deactivate` command is created when you activate your environment):
|
|
|
|
```
|
|
|
|
deactivate
|
|
|
|
```
|
|
|
|
|
|
|
|
After activating a virtualenv, you can install new packages without special permissions using `pip` (guide [here](https://packaging.python.org/tutorials/installing-packages/#installing-from-pypi)). Those packages will be only available within that virtualenv.
|
|
|
|
|