Which are the virtual environments create tools available in Python (like
yarn in Node.JS) and how are packages installed and handled using those tools?
There are also numerous pip installable alternatives to the above notably pipvenv.
The built in venv (and the older virtualenv) work by you creating your virtual environment once to a specified directory such as:
python -mvenv ./myvenv
This creates a copy, (in the specified directory), of python, pip and the standard libraries, (you can specify a specific version of python from those that you have installed). You can then, (at any time), activate it by running ./myvenv/bin/activate, on windows it is
- Modifies your path to point to the copies of python & pip
- Modifies your pythonpath to point to those under ./myvenv
While it is active any use of python will use that environment and pip will install to it. (Note that associations are not modified so just running somefile.py will use the same python as it normally would).
You can switch out of the venv with
Note that PEP 582 proposes Python local packages directory which, if implemented, will reduce the need for venv/virtualenv, etc.