Solved

Python27 and Python32

Posted on 2011-09-21
9
683 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

762 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