Creating a Python Virtual Environment on Debian 10
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
A Python virtual environment is an isolated project space on your system that contains its own Python executable, packages, and modules. Your Python applications and projects often have their own specific dependencies. With a virtual environment you can manage each of your project’s distinct dependencies without having them interfere with each other. You can use the virtualenv tool to create a virtual environment on your system. This guide shows you how to use virtualenv to create and run a Python virtual environment on a Debian 10 Linode.
Update your system:
sudo apt-get update && sudo apt-get upgradeThis guide is written for a non-root user. Commands that require elevated privileges are prefixed with
sudo. If you’re not familiar with the
sudocommand, you can check our Users and Groups guide.
Install the virtualenv tool using your package manager:
sudo apt install virtualenv
python-environmentsdirectory in your user’s home directory and navigate to it:
mkdir ~/python-environments && cd ~/python-environments
Create a Python virtual environment. By default, virtualenv attempts to use the Python 2.5 interpreter to create a new environment. Replace
envwith the name you would like to assign to your virtual environment.
If you would like to create a virtual environment using Python3, use the
--pythonoption to pass the Python version you’d like to use.
virtualenv --python=python3 env
The command creates a new directory with the name you assigned to your virtual environment. This directory contains all of the isolated files, packages, modules, and executables that is used by your new environment.
Validate that your environment is installed with the version of Python that you expect:
You should see your
envenvironments Python version:
Activate the newly created virtual environment:
The name of the working environment appears in parentheses after it’s created.
You can now begin installing Python packages and libraries that will remain isolated to your virtual environment.
To deactivate an active virtual environment, issue the following command:
Your virtual environment is deactivated and you should no longer see its name listed next to your command line’s prompt
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on