Discussion:
what is the easiest way to install multiple Python versions?
Albert-Jan Roskam
2014-10-12 13:33:05 UTC
Permalink
Hi,

(sorry for cross-posting)

A few days ago I needed to check whether some Python code ran with Python 2.6. What is the easiest way to install another Python version along side the default Python version? My own computer is Debian Linux 64 bit, but a platform-independent solution would be best.

Possible solutions that I am aware of

-make altinstall *). This is what I tried (see below), but not all modules could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and check my code in Python 2.6 (and I replaced a dict comprehension with a list comprehension, for example)
- ...

What is the recommended way? I don't expect/hope that I'd ever need something lower than Python 2.5

Thank you.

Albert-Jan


*) Make altinstall
sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev tk-dev zlib1g-dev
wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
tar -zxvf Python-2.6.8.tgz
cd Python-2.6.8/
./configure --prefix=/usr/local
make # see 'failed stuff' below
sudo make altinstall
mkvirtualenv -p /usr/local/bin/python2.6 python26 # ImportError: No module named zlib


# Failed stuff
Failed to find the necessary bits to build these modules:
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev ossaudiodev readline
sunaudiodev zlib





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris Angelico
2014-10-12 14:20:05 UTC
Permalink
On Mon, Oct 13, 2014 at 12:33 AM, Albert-Jan Roskam
Post by Albert-Jan Roskam
*) Make altinstall
sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev tk-dev zlib1g-dev
wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
tar -zxvf Python-2.6.8.tgz
cd Python-2.6.8/
./configure --prefix=/usr/local
make # see 'failed stuff' below
sudo make altinstall
mkvirtualenv -p /usr/local/bin/python2.6 python26 # ImportError: No module named zlib
# Failed stuff
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev ossaudiodev readline
sunaudiodev zlib
Generally, this is the method I would recommend. For a start, run this:

sudo apt-get build-dep python

This is in place of your explicit "apt-get install" command; Debian
keeps track of the dev packages needed to rebuild a given program, and
will go fetch them for you.

After that, just look at exactly what packages you're still lacking.
You may well find that you don't have all the dependencies for all
Python modules, as some of them might not be included in a basic
"apt-get install python" installation; the solution is a bit more
"apt-get build-dep" work, or some manual hunting down of dev packages
(which may well be easier in some situations).

But what version of Debian are you after, and why are you trying to
build a 2.6.8 from source? On Debian Wheezy, getting hold of Python
2.6 should be as easy as:

$ sudo apt-get install python2.6

I believe Squeeze ships 2.6 as its standard system Python, so it's
even easier. Are you on the unreleased Jessie? And why do you even
need 2.6 as opposed to 2.7?

ChrisA
Albert-Jan Roskam
2014-10-16 08:42:31 UTC
Permalink
----- Original Message -----
From: Chris Angelico <rosuav at gmail.com>
Cc: Python <python-list at python.org>
Sent: Sunday, October 12, 2014 4:20 PM
Subject: Re: what is the easiest way to install multiple Python versions?
On Mon, Oct 13, 2014 at 12:33 AM, Albert-Jan Roskam
Post by Albert-Jan Roskam
*) Make altinstall
sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev
tk-dev zlib1g-dev
Post by Albert-Jan Roskam
wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
tar -zxvf Python-2.6.8.tgz
cd Python-2.6.8/
./configure --prefix=/usr/local
make # see 'failed stuff' below
sudo make altinstall
mkvirtualenv -p /usr/local/bin/python2.6 python26 # ImportError: No module
named zlib
Post by Albert-Jan Roskam
# Failed stuff
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev ossaudiodev readline
sunaudiodev zlib
sudo apt-get build-dep python
Aha, useful tip. But won't this (re)build the dependencies of the default python version?
Or should I do sudo apt-get build-dep python-2.6?
This is in place of your explicit "apt-get install" command; Debian
keeps track of the dev packages needed to rebuild a given program, and
will go fetch them for you.
After that, just look at exactly what packages you're still lacking.
You may well find that you don't have all the dependencies for all
Python modules, as some of them might not be included in a basic
"apt-get install python" installation; the solution is a bit more
"apt-get build-dep" work, or some manual hunting down of dev packages
(which may well be easier in some situations).
But what version of Debian are you after, and why are you trying to
build a 2.6.8 from source? On Debian Wheezy, getting hold of Python
$ sudo apt-get install python2.6
I believe Squeeze ships 2.6 as its standard system Python, so it's
even easier. Are you on the unreleased Jessie? And why do you even
need 2.6 as opposed to 2.7?
I am on Debian 7.6, Wheezy (Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux). Wow, so it is really this simple? This was actually the first option I considered, but I was sooooo paranoid to ruin my default Python version.

Reason why I need Python 2.6? The script needs to run on a server that turned out to have Python 2.6. It is beyond my power to upgrade the Python version.

Thanks all!
Chris Angelico
2014-10-16 08:48:31 UTC
Permalink
Post by Albert-Jan Roskam
From: Chris Angelico <rosuav at gmail.com>
sudo apt-get build-dep python
Aha, useful tip. But won't this (re)build the dependencies of the default python version?
Or should I do sudo apt-get build-dep python-2.6?
It would install (not usually build) all the dependencies of the
default Python, yes; but if you're compiling from source, that's
usually going to be fairly close. For instance, if you want to build
Python 3.5 from Mercurial, the easiest way to get started would be
"apt-get build-dep python3"; that might not get absolutely everything,
but it's sure going to be close. Python's dependencies don't change
hugely between minor versions.
Post by Albert-Jan Roskam
But what version of Debian are you after, and why are you trying to
build a 2.6.8 from source? On Debian Wheezy, getting hold of Python
$ sudo apt-get install python2.6
I am on Debian 7.6, Wheezy (Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux). Wow, so it is really this simple? This was actually the first option I considered, but I was sooooo paranoid to ruin my default Python version.
I'm fairly sure - though you could easily confirm - that installing
the python2.6 package won't fiddle with the name "python", nor the
name "python2", but will simply add another name "python2.6". I have
it installed on my main Wheezy system, and that's how it is. Not sure
if there's a way to tweak that with update-alternatives or anything.
Post by Albert-Jan Roskam
Reason why I need Python 2.6? The script needs to run on a server that turned out to have Python 2.6. It is beyond my power to upgrade the Python version.
Thanks all!
Fair enough. The differences between 2.6 and 2.7 aren't great, though,
so you may well be able to port it trivially. But in any case, so long
as you have Wheezy, you should be able to run 2.6 the easy way.

ChrisA
Albert-Jan Roskam
2014-10-16 12:31:29 UTC
Permalink
----- Original Message -----
From: Chris Angelico <rosuav at gmail.com>
Cc: Python <python-list at python.org>
Sent: Thursday, October 16, 2014 10:48 AM
Subject: Re: what is the easiest way to install multiple Python versions?
On Thu, Oct 16, 2014 at 7:42 PM, Albert-Jan Roskam <fomcl at yahoo.com>
<snip>
The differences between 2.6 and 2.7 aren't great, though,
so you may well be able to port it trivially. But in any case, so long
as you have Wheezy, you should be able to run 2.6 the easy way.
Most things were indeed easy to solve. But this one surprised me. With Python 2.6, I need to outcomment the 'lambda' line. The error is what I get in Python 2.6. It does not matter if I do u"\n".join(het_logboek[i:]). I don't use latin-1 anywhere in my program. I need to convert unicode to bytes in Python 2.6, or else it chokes in the smart quote.


import codecs
import os
import time


def print_log_van_vandaag(logbestand):
"""Print today's log. The Cron Daemon will mail this"""
vandaag = time.strftime("%Y-%m-%d")
with codecs.open(logbestand, encoding="utf-8") as logboek:
het_logboek = logboek.readlines()
#het_logboek = map(lambda x: x.encode("utf-8"), het_logboek) # bug in Python 2.6?
for i, regel in enumerate(het_logboek):
if regel.startswith(vandaag):
print os.linesep.join(het_logboek[i:])
break
Traceback (most recent call last):
File "mailer.py", line 410, in <module>
print_log_van_vandaag("mailer.log")
File "mailer.py", line 399, in print_log_van_vandaag
print os.linesep.join(het_logboek[i:])
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2018' in position 10214: ordinal not in range(256)
Chris Angelico
2014-10-16 14:59:32 UTC
Permalink
Post by Albert-Jan Roskam
Most things were indeed easy to solve. But this one surprised me. With Python 2.6, I need to outcomment the 'lambda' line. The error is what I get in Python 2.6. It does not matter if I do u"\n".join(het_logboek[i:]). I don't use latin-1 anywhere in my program. I need to convert unicode to bytes in Python 2.6, or else it chokes in the smart quote.
Hmm, that looks like a configuration difference between the two,
rather than a major breaking difference. It'll depend on the console
settings; if you're running 2.6 from cron, but 2.7 from the console
(or the other way around), you'll see stuff like this break.

It's also possible that a bug was discovered, of course, but what
exactly the bug is, I can't say. The error you're seeing is perfectly
correct: you have Unicode character U+2018 (a curly quote) in your
stream, and the print statement is trying to send that to a Latin-1
output, and that's not going to work. The question is, why is your
console believed to be set to Latin-1? And if encoding UTF-8 works,
then there's something very VERY wrong. (Unless by "works" you just
mean "doesn't throw an error", and the UTF-8 bytes are being
interpreted as Latin-1 bytes.)

ChrisA

Gayathri J
2014-10-12 16:15:35 UTC
Permalink
I have been using Anaconda's (Continnum) conda installation for system
installation (python 2.7) and for python 3

conda lets us maintain diferent environments with different python and
different combinations of other packages like numpy etc...

sure not to disappoint!
Post by Albert-Jan Roskam
Hi,
(sorry for cross-posting)
A few days ago I needed to check whether some Python code ran with Python
2.6. What is the easiest way to install another Python version along side
the default Python version? My own computer is Debian Linux 64 bit, but a
platform-independent solution would be best.
Possible solutions that I am aware of
-make altinstall *). This is what I tried (see below), but not all modules
could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran
Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and
check my code in Python 2.6 (and I replaced a dict comprehension with a list
comprehension, for example)
- ...
What is the recommended way? I don't expect/hope that I'd ever need
something lower than Python 2.5
Thank you.
Albert-Jan
*) Make altinstall
sudo apt-get install libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev
tk-dev zlib1g-dev
wget https://www.python.org/ftp/python/2.6.8/Python-2.6.8.tgz
tar -zxvf Python-2.6.8.tgz
cd Python-2.6.8/
./configure --prefix=/usr/local
make # see 'failed stuff' below
sudo make altinstall
mkvirtualenv -p /usr/local/bin/python2.6 python26 # ImportError: No module named zlib
# Failed stuff
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev ossaudiodev readline
sunaudiodev zlib
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
https://mail.python.org/mailman/listinfo/python-list
Albert-Jan Roskam
2014-10-16 08:45:12 UTC
Permalink
----- Original Message -----
From: Gayathri J <usethisid2014 at gmail.com>
To: Albert-Jan Roskam <fomcl at yahoo.com>
Cc: Python <python-list at python.org>
Sent: Sunday, October 12, 2014 6:15 PM
Subject: Re: what is the easiest way to install multiple Python versions?
I have been using Anaconda's (Continnum) conda installation for system
installation (python 2.7) and for python 3
conda lets us maintain diferent environments with different python and
different combinations of other packages like numpy etc...
sure not to disappoint!
Thanks! Yeah, Anaconda seams very promising. I am also curious about numba, which is part of conda IIRC. Curious how it compares to Cython. Awesome that it's possible to add a numba decorator to speed up an arbitrary function.
Terry Reedy
2014-10-13 00:54:45 UTC
Permalink
Post by Albert-Jan Roskam
A few days ago I needed to check whether some Python code ran with
Python 2.6. What is the easiest way to install another Python version
along side the default Python version? My own computer is Debian
Linux 64 bit, but a platform-independent solution would be best.
Installation is platform dependent. On Windows, the answer would simply
be 'get the PSF x.y installer and run it'.
--
Terry Jan Reedy
Albert-Jan Roskam
2014-10-16 08:47:43 UTC
Permalink
----- Original Message -----
From: Terry Reedy <tjreedy at udel.edu>
To: python-list at python.org
Sent: Monday, October 13, 2014 2:54 AM
Subject: Re: what is the easiest way to install multiple Python versions?
Post by Albert-Jan Roskam
A few days ago I needed to check whether some Python code ran with
Python 2.6. What is the easiest way to install another Python version
along side the default Python version? My own computer is Debian
Linux 64 bit, but a platform-independent solution would be best.
Installation is platform dependent. On Windows, the answer would simply
be 'get the PSF x.y installer and run it'.
Thank you. Yes, for Windows it is easy. I was just scared that I would accidentally replace my default Python version 2.7 with 2.6 --and ruin my system.
Rustom Mody
2014-10-13 02:31:28 UTC
Permalink
Post by Albert-Jan Roskam
Hi,
A few days ago I needed to check whether some Python code ran with Python 2.6. What is the easiest way to install another Python version along side the default Python version? My own computer is Debian Linux 64 bit, but a platform-independent solution would be best.
Possible solutions that I am aware of
-make altinstall *). This is what I tried (see below), but not all modules could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and check my code in Python 2.6 (and I replaced a dict comprehension with a list comprehension, for example)
Hearing a bit about docker nowadays.

Here's why its supposedly better than a VM:
https://www.docker.com/whatisdocker/

Downsides?? No idea!
Chris Angelico
2014-10-13 07:54:11 UTC
Permalink
Post by Rustom Mody
Hearing a bit about docker nowadays.
https://www.docker.com/whatisdocker/
Downsides?? No idea!
One obvious downside is that it doesn't allow guests to modify the OS
at all. A VM gives you an entire OS, so you can use and manipulate
anything. If you don't *need* all that flexibility, then a VM is
paying an unnecessary cost, ergo Docker will have no downside.

ChrisA
Rustom Mody
2014-10-13 08:00:10 UTC
Permalink
Post by Chris Angelico
Post by Rustom Mody
Hearing a bit about docker nowadays.
https://www.docker.com/whatisdocker/
Downsides?? No idea!
One obvious downside is that it doesn't allow guests to modify the OS
at all. A VM gives you an entire OS, so you can use and manipulate
anything. If you don't *need* all that flexibility, then a VM is
paying an unnecessary cost, ergo Docker will have no downside.
Was talking of more pragmatic downsides eg "Does it really work?" :-)
[Docker is still quite new]
Chris Angelico
2014-10-13 13:50:27 UTC
Permalink
Post by Rustom Mody
Post by Chris Angelico
Post by Rustom Mody
Hearing a bit about docker nowadays.
https://www.docker.com/whatisdocker/
Downsides?? No idea!
One obvious downside is that it doesn't allow guests to modify the OS
at all. A VM gives you an entire OS, so you can use and manipulate
anything. If you don't *need* all that flexibility, then a VM is
paying an unnecessary cost, ergo Docker will have no downside.
Was talking of more pragmatic downsides eg "Does it really work?" :-)
[Docker is still quite new]
Ah, I can't help you there. I've never used Docker.

ChrisA
Albert-Jan Roskam
2014-10-16 08:32:22 UTC
Permalink
----- Original Message -----
From: Rustom Mody <rustompmody at gmail.com>
To: python-list at python.org
Sent: Monday, October 13, 2014 10:00 AM
Subject: Re: what is the easiest way to install multiple Python versions?
Post by Chris Angelico
Post by Rustom Mody
Hearing a bit about docker nowadays.
https://www.docker.com/whatisdocker/
Downsides?? No idea!
One obvious downside is that it doesn't allow guests to modify the OS
at all. A VM gives you an entire OS, so you can use and manipulate
anything. If you don't *need* all that flexibility, then a VM is
paying an unnecessary cost, ergo Docker will have no downside.
Was talking of more pragmatic downsides eg "Does it really work?" :-)
[Docker is still quite new]
I have not used Docker before but I did look into it. Reason why I chose I full VM (Virtualbox in conjunction with Jenkins CI) is that I also needed to test Windows platforms. AFAIK, the Docker guest systems *must* be unix, possibly only Linux. A big plus of Docker is that the guest systems share resources, so it is a lot lighter to run multiple guest machines. I did hear that nowadays it is possible to use a Windows *host* system.
Ned Batchelder
2014-10-13 14:31:28 UTC
Permalink
Post by Albert-Jan Roskam
Hi,
(sorry for cross-posting)
A few days ago I needed to check whether some Python code ran with Python 2.6. What is the easiest way to install another Python version along side the default Python version? My own computer is Debian Linux 64 bit, but a platform-independent solution would be best.
Possible solutions that I am aware of
-make altinstall *). This is what I tried (see below), but not all modules could be built. I gave up because I was in a hurry
-Pythonbrew. This project is dead
-Deadsnakes
-Anaconda
-Tox? I only know this is as a cross-version/implementation test runner
-Vagrant. This is what I eventually did, and this was very simple. I ran Ubuntu 10.0.4 LTS, which uses Python 2.6, and used Vagrant SSH to run and check my code in Python 2.6 (and I replaced a dict comprehension with a list comprehension, for example)
- ...
What is the recommended way? I don't expect/hope that I'd ever need something lower than Python 2.5
I use pythonz: http://saghul.github.io/pythonz/ It lets me specify not
just the version I want, but the implementation I want: I can install
CPython 2.6.1, PyPy 2.0.2, and Jython 2.5.3 all the same way.
--
Ned Batchelder, http://nedbatchelder.com
Continue reading on narkive:
Loading...