?
Solved

Python27 and Python32

Posted on 2011-09-21
9
Medium Priority
?
706 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 400 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 29

Assisted Solution

by:pepr
pepr earned 200 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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
 
LVL 17

Assisted Solution

by:gelonida
gelonida earned 400 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 17

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 17

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

752 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