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

2

6

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

Instance answered 31/1, 2018 at 15:15 Comment(1)
suggest that split out into 1) your question about how to upgrade pip versions 2) your question about which version of pip to install virtualenvMayapple
G
10

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
Gelinas answered 31/1, 2018 at 19:43 Comment(1)
I activated with source/env/bin/activate but the python version stayed as 3.6 not 2.7 as I declared.Journeyman
P
0

Try using conda to set up virtual environments ?

With conda you can create a virtual environment and keep each of them separate from the root environment.

Percentage answered 31/1, 2018 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.