How do you switch between python 2 and 3, and vice versa? -


i reading how learn python hard way, uses 2. discovered invent python, uses 3.

can download python 3, , use when read invent python, switch python 2 when want read how learn python hard way. if so, how choose version use?

using 'virtualenv' can have different isolated python environments on single machine. can switch any-time between different python interpreter versions.

what virtualenv?

a virtual environment isolated working copy of python allows work on specific project without worry of affecting other projects. enables multiple side-by-side installations of python, 1 each project. doesn’t install separate copies of python, provide clever way keep different project environments isolated.

how install?

pip install virtualenv 

to create virtual environment python 2.7 :

root:~# python2.7  /usr/bin/python2.7 

root:~# python3.4  /usr/local/bin/python3.4 

you can use python interpreter of choice:

root:~# virtualenv -p /usr/bin/python2.7 vpy27  running virtualenv interpreter /usr/bin/python2.7  new python executable in /root/vpy27/bin/python2.7  creating executable in /root/vpy27/bin/python  installing setuptools, pip, wheel...done. 

to begin using virtual environment, needs activated:

root:~# source vpy27/bin/activate 

the name of current virtual environment appear on left of prompt:

(vpy27) root:~# python -v python 2.7.3 

install packages usual, example:

(vpy27) root:~# pip install junos-eznc    >> pip installs done here, available in environment. 

if done working in virtual environment moment, can deactivate it:

(vpy27) root:~# deactivate    

to create virtual environment python 3.4:

root:~# python3.4  /usr/local/bin/python3.4  root:~# virtualenv -p /usr/local/bin/python3.4 vpy34  root:~# source vpy34/bin/activate  (vpy34) root:~# python -v python 3.4.4 

there way create virtual environment available site-packages.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -