Python Virtual Environment

We can use python virtual  Environment to create many isolated project on our machine.
In Ubuntu 16.04, we first need to install python3-pip


$ sudo apt-get install -y python3-pip

Once it is installed we can use pyvenv command to create an isolated project.
For example:


$ pyvenv testEnv
oren@oren-computer:~/workspace/pythonEnvs
$ cd testEnv/
/home/oren/workspace/pythonEnvs/testEnv
oren@oren-computer:~/workspace/pythonEnvs/testEnv
$ ls
bin  include  lib  lib64  pyvenv.cfg  share

As we can see the pyvenv create a new folder and insert into this folder some basic files and folders.
To activate our project environment we need to run:
source <ourProjectDirectory>/bin/activate
After running this command python will also run python3.
We will also see the name of the project in the terminal prompt.
Once we finish working and want to deactivate we can just run:
deactivate

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s