Venv is used when separating the Python execution environment, such as when you want to change the Python execution environment for each project or when you do not want to pollute the local environment. You can easily create a virtual environment for each project by collecting the dependencies of Python binaries and libraries under an arbitrary directory and overwriting PATH.
##Installation(Ubuntu20.04)
$ sudo apt install python3-venv
$ python3.7 -m venv PJ001
$ ls PJ001/
bin  include  lib  lib64  pyvenv.cfg  share
##Create virtual environment
$ source PJ001/bin/activate
(PJ001) $ 
##When exiting
(PJ001) $ deactivate
The Python executable file of the virtual environment and the executable file of other packages are placed in bin. Library files used in the virtual environment are placed in lib and ʻinclude (new packages added after ʻactivate are installed underlib / pythonX.Y / site-packages /). Execute deactivate to exit.
A similar tool that has been around for a long time is virtualenv. It is recommended to use venv for Python 3.4 or later.
Recommended Posts