DEV Community

petercour
petercour

Posted on

Virtual environments in Python

Python installs modules system wide. This is unlike other programming languages where you need to import modules.

System wide installs of modules can create conflicts, you want virtual environments.

on Ubuntu Linux

Setup virtual environment
On Ubuntu 18.x:

sudo apt-get install python3-venv

On other systems, you need another command to install. It's highly likely its installed by default on Mac and Windows.

Create Virtual Environment

Create Virtual Environment in the command line.
To create a new virtual environment:

python3.6 -m venv test

or

pyvenv test

Activate Virtual Environment

After creation, you need to activate virtual environment.
To activate the virutal environment

cd venv
source bin/activate

Then modules are only installed in the virtual environment, not conflicting with other python programs.

Learn Python

Oldest comments (0)