Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup virtual environment for python(2.7, 3.5, 3.6) on Ubuntu16.04 LTS?

I've read a lot of blog post about this and I'm still confused as to what is "best" way to set it up. Most of the blog posts I've read are out-dated. I'm new to Linux and have messed up my system twice now and still can't setup the virtual environments properly. According to what I've read, Virtualenv and Virtualenvwrapper combination is the most widely used setup. So, After a fresh Ubuntu 16.04 LTS install, I do the following:

Install Python 3.6 as shown in the following link.
https://tecadmin.net/install-python-3-6-ubuntu-linuxmint/
The current state of the system now is,
$ python3.6 -V
Python 3.6.4

$ pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

pip3 (python3.5) and pip(python2.7) do not come pre-installed. To install them , I do:
$ sudo apt-get install python-pip
$ sudo apt-get install python3-pip

$ which pip
/usr/bin/pip

$ which pip3
/usr/bin/pip3

Now, the pip-version installed through apt-get method is old(version 8.1.1). We need to update it to (version 9.0.1). This is where it all goes wrong.
Question 1: How do I update the two different pip versions without breaking anything?

Assume, both pip versions are upgraded to version 9.0.1
Now, I have to install virtualenv and virtualenvwrapper.
Which pip version do I use to install it?

$ pip install --user virtualenv and $ pip install --user virtualenvwrapper
or
$ pip3 install --user virtualenv and $ pip3 install --user virtualenvwrapper

ps: I'm following this link-
http://chrisstrelioff.ws/sandbox/2016/09/21/python_setup_on_ubuntu_16_04.html

like image 494
alligator123 Avatar asked Jan 31 '18 15:01

alligator123


1 Answers

With python 3.6 virtual environments come built-in with the venv module:

python3.6 -m venv my-venv

To create a virtual environment for python 3.5:

virtualenv -p python3.5 env

To create a virtual environment for python 2.7:

virtualenv -p python2.7 env
like image 173
tread Avatar answered Sep 24 '22 01:09

tread