Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Python27 and Python32

Posted on 2011-09-21
9
Medium Priority
?
710 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

609 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