The virtual environment in Python allows you to isolate projects from each other for more convenient management, projects placed in a virtual environment can use different modules and dependencies, including their different versions, which makes the administration of such projects very convenient.
To create a virtual Python environment, log in with SSH or WEB-SSH .
Go to the directory in which you want to create a virtual environment
cd www/py-projects/
Create the virtual environment using the command for the required Python version . venv-project is an arbitrary project name, do not forget to change it, and as a result of executing the command, a directory with this name will be created.
Variant for Python 3.7
/opt/alt/python37/bin/python3 -m virtualenv venv-project
Variant for Python 3.8
/opt/alt/python38/bin/python3 -m venv venv-project
Activate the virtual environment by referring to the activate file inside the bin directory of the created project . Its name in the lower left corner of the console will indicate that the virtual environment has been successfully activated.
source /venv-project/bin/activate
Go to the bin directory of the created project
cd venv-project/bin/
By default, bin directory will contain the python interpreter of the selected version and the pip module manager, you need to run scripts or use the pip module manager from the bin directory.
To deactivate (exit) the virtual environment, execute the command
deactivate
To delete a virtual environment, it is enough to simply destroy the directory with its name in which it was created
rm -rf venv-project/
All question categories