1 - The virtualenv module
Python has a module named virtualenv to create a virtual python environment, that is, an isolated working copy of Python that allows you to work on a specific project without affecting other projects. So basically it's a tool that allows multiple side-by-side installations of Python, i.e. a clean install for each project.
2 - Creation of a virtual environment under Linux
is not installed in your system, please install it through the terminal shell by typing the command:
$ sudo apt-get install python-pip
Then install the
module by typing:
$ pip install virtualenv
Now check your installation
$ virtualenv --version
Then create a virtual environment:
$ virtualenv my_venv
After this command, a folder named my_venv will be created. If you want to create a
for a specific version of python, type:
$ virtualenv -p / usr / bin / python3 my_venv
or
$ virtualenv -p / usr / bin / python2.7 my_venv
Now we have to finally activate it using the command
$ source my_venv / bin / activate
You are now in a Python virtual environment You can turn it off using
$ deactivate
3 - Creation of Python virtualenv on Windows
To create a
in Windows, just follow the following steps: Run the cmd command and navigate to your project directory using the cd command Install virtualenv by typing in the command:
pip install virtualenv
Now in whatever directory you are, this line below will create a virtualenv:
virtualenv my_venv
Now, if you are in the same directory, activate your virtual environment by typing:
my_venvScriptsactivate.bat
You can deactivate your virtualenv by typing the cmd command:
deactivate
my-courses.net