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
Solved

Python27 and Python32

Posted on 2011-09-21
9
696 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 29

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

829 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