Solved

Python27 and Python32

Posted on 2011-09-21
9
688 Views
Last Modified: 2012-05-12
Hi

I have installed Python32 on a Ubuntu system. Python27 had already been installed. If I type python in the terminal the 2.7 version starts. How did I start Python 3.2. Further, when I install new modules, do I need to tell the system which version gets the modules?? If so, how do I do it?

Thanks in advance

Issac
0
Comment
Question by:IssacJones
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 100 total points
ID: 36576715
run
dpkg -L python3.2
  to get the file list of the python3.2

Say the binary executable of python3.2 is  /usr/bin/python3.2 (do "ls  -l /usr/bin/python3.2" to check), then
change the symbolic link of /usr/bin/python to it.
sudo mv /usr/bin/python  /usr/bin/python27
sudo  ln  -s  /usr/bin/python3.2   /usr/bin/python

Verify:
python --version
0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 50 total points
ID: 36576757
I suggest to rename only the less used Python to say python3.  You will soon get the Python 3.3, you will throw away the Python 3.2, and you do not want to fix all your magic lines in the Python scripts.
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36576804
Just checked on Ubuntu:
sudo mv /usr/bin/python  /usr/bin/python2
sudo  ln  -s  /usr/bin/python3.2mu   /usr/bin/python
sudo  ln  -s  /usr/bin/python3.2mu   /usr/bin/python3

So in your script, you can either do
#!/usr/bin/python3
or
#!/usr/bin/python

For the script only work on python2.x, use
#!/usr/bin/python2
0
 

Author Comment

by:IssacJones
ID: 36576845
Thanks guys - but what do I do about modules I install? do I need to specifically load them for each of the different versions of python? If so, how do I do that?

By the way, I'm new to Linux
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 16

Assisted Solution

by:gelonida
gelonida earned 100 total points
ID: 36576848
in order to start  python 2.7
type
python2.7
or just python as lon as you do NOT change the smbolic link to /usr/bin/python

in order to start python 3.2
Just type
python3.2

If you write your own script, then use the 'shebang line as first line of your script'
For your default python this would be
#!/usr/bin/env python

For python 2.7
#!/usr/bin/env python2.7

For python 3.2 this would be
#!/usr/bin/env python3.2


If you are using virtualenv for python 2.7 or older, then please pay attention when following Wesley's
suggestion of changing the symbloic link pointing to /usr/bin/python

virtualenv would stop working if you changed this symlink to a python 3 version.

This is easy to fix though:
just change the first line of /usr/bin/virtualenv to point to  /usr/bin/python2.7
0
 
LVL 16

Expert Comment

by:gelonida
ID: 36576912
I am not sure how ubuntu handles python modules in your case.

On my system I installed python 2.6 and 3.1  (However I don't use 3.1, It's just installed)
Python 3 has still very little appeal to me due to the huge amount of not supported libraries.

I could imagine, that Ubuntu installs python modules for all installed versions (if the module supports both version)
However I'm not sure about this.

For python 2.7 module management you could use virtualenv  ( http://mitchfournier.com/2010/06/25/getting-started-with-virtualenv-isolated-python-environments/ ) This allows you also to install modules, which are not supported by ubuntu.

However I don't know the recommended way of installing custom python 3 packages without conflicting with Ubuntu package management
0
 
LVL 16

Expert Comment

by:gelonida
ID: 36576927
+1 on Pepr's sugegstion to create a symlink to

/usr/bin/python3
In most cases you're just interested in the difference between python 2.x and python 3.x
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36576933
> what do I do about modules I install?
The binary executable of python will take care of it.
If the module you installed for python3.2, it will be installed under /usr/lib/python3.2/
The /usr/bin/python3.2mu will find the right module to load.
0
 

Author Closing Comment

by:IssacJones
ID: 36577010
Many thanks to you all!!!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
linux boot fsck problem 3 61
linux ssh 4 59
Exchange 2010 unable to mount DB due to corruption 11 71
How to use pyenv 4 16
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now