Python virtualenv
Last updated
Was this helpful?
Last updated
Was this helpful?
virtualenv
is a tool to create isolated Python environments. You can read more about it in the . This article provides a quick summary to help you set up and use a virtual environment.
If you’re running Ubuntu 16.04 LTS (or and earlier version), Python 3.5 is likely installed by default. Don’t remove it! To get Python 3.6, follow the instructions in this section.
Run the following command to add the Python 3.6 PPA.
Check for updates and install Python 3.6 via the following commands.
Now you have three Python version, use python
to run version 2.7, python3
for version 3.5, and python3.6
for version 3.6.
For more information on this subject, check out Ji m’s article .
cd
to your project directory and run virtualenv
to create the new virtual environment.
The following commands will create a new virtual environment under my-project/my-venv.
Now that we have a virtual environment, we need to activate it.
After you activate the environment, your command prompt will be modified to reflect the change.
After you activate the virtual environment, you can add packages to it using pip
. You can also create a description of your dependencies using pip
.
The following command creates a file called requirements.txt
that enumerates the installed packages.
This file can then be used by collaborators to update virtual environments using the following command.
To return to normal system settings, use the deactivate
command.
After you issue this command, you’ll notice that the command prompt returns to normal.