DEV Community

Konstantinos Blatsoukas
Konstantinos Blatsoukas

Posted on

venv

python vevnv

Is used for separating packages versions per project.
For example, one project may use a package named foo-1-0, but another project uses foo-2-0.
We can not separate them using the global environment.
The solution is, to create two different virtual environemnts.

list all global packages

pip list # list all packages
Enter fullscreen mode Exit fullscreen mode

create a new virtual environment

# a new virtual environment with name project_env will be craeted
python -m venv project_env 
Enter fullscreen mode Exit fullscreen mode

activate venv

activate

# activate on ubuntu
source myenv/bin/activate
Enter fullscreen mode Exit fullscreen mode

deactivate venv

deactivate
Enter fullscreen mode Exit fullscreen mode

generate packages version for requirements.txt

pip freeze
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

generate required python packages

python -m venv vevn
source vevn/bin/activate
pip install pip-tools
pip-compile requirements.in
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (0)