3. Python run environment¶
Python can be launched in couple ways.
3.1. Virtual Environment (venv)¶
Keeps environment separate,
Solves problem of dependencies, packages conflicts,
Helps keeping different python/libraries in our projects
Note
In order to create virtual environment we do one of below commands
- python -m venv <DIR>
instead DIR usually we use venv or env
- virtualenv <KATALOG>
ex. virtualenv venv
Note
In order to use environments we need to execute:
source venv/bin/activate
Hint
In case of Windows user is activating env withouth source command.
venv\Scripts\activate.bat
3.2. Global environment¶
All packages are global - there is no separation,
There might problems with dependencies
3.3. Environment in container¶
Python available within container,
Good in case of testing solutions,
Integral part of nowadays CI/CD environments
3.4. Creation of new environment¶
python -m venv venv
,source venv/bin/activate
,
3.5. Installation of new packages inside of environment¶
Optional step
pip freeze
,pip install <package_name>
,pip freeze
Just to verify what has been installed,Optional step
pip freeze > requirements.txt
3.6. Exercise¶
This exercise will show you typical use case of virtual environments.
Attention
Create new virtual environment,
Activate virtual env,
Look on
pip freeze
,Install django,
Look on
pip freeze
,Deactivate virual env,
Remove virtual env,
Start from scratch,
Install notebook