Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save graywen24/470a17f1c34c930a8f16fd7744bc328c to your computer and use it in GitHub Desktop.
Save graywen24/470a17f1c34c930a8f16fd7744bc328c to your computer and use it in GitHub Desktop.
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 

Now create a virtual environment

virtualenv venv 

you can use any name insted of venv

You can also use a Python interpreter of your choice

virtualenv -p /usr/bin/python2.7 venv

Active your virtual environment:

source venv/bin/activate

Using fish shell:

source venv/bin/activate.fish

To deactivate:

deactivate

Create virtualenv using Python3

virtualenv -p python3 myenv

Instead of using virtualenv you can use this command in Python3

python3 -m venv myenv

add virtualevnwrapper

sudo apt-get install virtualenvwrapper

create new virtualenv

root@lab:/tmp#mkvirtualenv test3
New python executable in /root/.virtualenvs/test3/bin/python
Installing setuptools, pip, wheel...done.
(test3) root@lab:/tmp#

exit the env

(test3) root@lab:~/.virtualenvs# deactivate

check current env

root@lab:~# workon
test3
test4

go inside a env

root@lab:~# workon test3
(test3) root@lab:~# pip list

install new package under the env

(test3) root@lab:~# pip list
pip (9.0.1)
setuptools (36.6.0)
wheel (0.30.0)
(test3) root@lab:~# pip install requests
requests (2.18.4)
(test3) root@lab:~# pip uninstall requests
no more requests (2.18.4)

this will not impact other env eg, test4 still the same packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment