Manage multi version python

I need to install a multi version of my project because:

– one of my project using python2.7
– other projects need using python3

So the best way is I using virtualenv for managing each project. It is quite complex for me, but here they are my resume after research from couple reference sites:

http://bhfsteve.blogspot.jp/2012/05/run-multiple-python-versions-on-your.html
https://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa
https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes/+index?batch=75&memo=75&start=75
http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/

A. Get multiple python versions installed

Add ppa for this ppa:

https://launchpad.net/~fkrull/+archive/deadsnakes

To install it (per the instructions in the link above), you do the following:

 sudo add-apt-repository ppa:fkrull/deadsnakes

Then you need to update your cache:

 sudo apt-get update

In my environment, after adding ppa, it was showing me an error message: ‘unmet dependencies’. What I do for fixing this error was:

 sudo apt-get clean
 sudo apt-get autoclean
 sudo apt-get -f install
 sudo dpkg --configure -a

Then run again

 sudo apt-get -f install

After that, I install python3.6:

 sudo apt-get install python3.6

Check which version if run this command in your terminal:

 python
 seti@lxle-SVE14112EGP:~/whatsapp-web$ python
 Python 2.7.12 (default, Nov 19 2016, 06:48:10)
 [GCC 5.4.0 20160609] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>>

That’s version 2.7 for default. Where is the version 3.6? Check to /usr/bin directory:

seti@lxle-SVE14112EGP:/usr/bin$ ls python*
python python3 python3m
python2 python3.5 python-argcomplete-check-easy-install-script3
python2.7 python3.5m python-config
python2.7-config python3.6
python2-config python3.6m

Two version of python run together in the same system: 2.7 and 3.6

B. Use virtualenv to manage my project and package installation. Install virtualenv:

sudo apt-get install python-virtualenv

Go to project directory:

seti@lxle-SVE14112EGP:/$ cd /home/seti/whatsapp-web/
seti@lxle-SVE14112EGP:~/whatsapp-web$

Run virtualenv to create the environment for the project:

virtualenv -p /usr/bin/python3.6 /env
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/seti/whatsapp-web/.env/bin/python3.6
Not overwriting existing python script /home/seti/whatsapp-web/.env/bin/python (you must use /home/seti/whatsapp-web/.env/bin/python3.6)
Installing setuptools, pkg_resources, pip, wheel...done.

Activate the environment:

source .env/bin/activate
(.env) seti@lxle-SVE14112EGP:~/whatsapp-web$

Check python version for the environment:

which python /home/seti/whatsapp-web/.env/bin/python
python
Python 3.6.2 (default, Jul 17 2017, 23:14:31)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

As you can see above, my environment using 3.6 python version. In the end, I want to end my work in the current environment, I have to deactivate the envy, use this command:

(.env) seti@lxle-SVE14112EGP:~/whatsapp-web$ deactivate
seti@lxle-SVE14112EGP:~/whatsapp-web$

 

 

 

Advertisements

About this entry