successfully install python 2.6.1 on ubuntu

General discussions related to Python.

Moderators: KDoiron, ChrJim, mawe, python

successfully install python 2.6.1 on ubuntu

Postby CryingSaul on Tue Jan 20, 2009 5:19 pm

after several trials and tribulations, i finally managed to get a independent python 2.6.1 version running smoothly on ubuntu 8.10, without interfering with the system's reliance on 2.5 and without breaking the entire package dependency system. it has been a nightmare, lived-through with the precious help of wacky, a member of this forum.

a lot of the following information will be obvious to people with a good knowledge of both linux and python. however, coming from mac osx, things haven't been that obvious. for the poor souls who will be frantically googling for "zlib", "zipimport.ZipImportError", "setuptools", "ipython", "readline" and "ubuntu", i would like to present a solution which, so far, hasn't disturbed the operating system and allows one to run ipython (and a lot more) without pulling one's hair out. it's actually quick and easy and involves no hacking whatsoever (i wouldn't know how to hack neither python nor linux anyhow).

disclaimer: my knowledge of linux is very limited. i write the following with the intent of helping out newbies such as myself. please do not hold me reponsible if you follow my procedure and end up with a system that's pushing up the daisies.

note: all of the above and below is valid for the gnome desktop environment. i haven't tried it with kde and, now that it's finally working, i don't think i will.

  • install a fresh copy of ubuntu 8.10 if your system has been hopelessly pulverized by trials, errors and packages scattered in the wrong places.

  • before doing anything directly related to python, you need to install the following packages. the easiest way is to open a terminal session and type sudo aptitude install package-name, for each and every package below. this list is an amalgam of several suggestions i found around the web, so one package or more might not be absolutely essential. but since it works, here's the list:

    • build-essential
    • libncursesw5-dev
    • libreadline5-dev
    • libssl-dev
    • libgdbm-dev
    • libbz2-dev
    • libc6-dev
    • libsqlite3-dev
    • libdb-dev
    • tk-dev
  • download and extract the python 2.6.1 source. from inside the source directory, enter ./configure --prefix=/home/yourusername/python. ignore, of course, the period that precedes this sentence. this will setup python to install into a 'python' directory inside your home directory, far away from anything system-like.

  • type make. at the output's end, you might get a couple of modules which can't be found. i don't remember their names but from searching around i gather that a lot of people can't seem to find them and that nobody really cares. most importantly, make sure that you don't get a module missing error for zlib or readline, which are essential for the following steps. the packages installed previously will have taken care of that, though.

  • type sudo make install. i tried to do a sudo make altinstall (after going through the python source readme file), but for some reason i ended up without an executable. so just go through a regular install.

  • now, if you type python you should get the default ubuntu python version (currently 2.5.2). typing which python should point to /usr/bin/python, not to the directory you just installed 2.6.1 into. all of this is normal and is actually what you'd want.

  • optional: if you need an additional python module (such as numpy), install it from its source directory by typing sudo /home/yourusername/python/bin/python setup.py install --prefix=/home/yourusername/python. this runs the setup script with the 2.6.1 interpreter and install the module into the 2.6.1 directory (since we're using the same prefix we specified when installing python itself).

  • create a symbolic link to the 2.6.1 interpreter so that the next step doesn't blow up in your face: sudo ln -s /home/yourusername/python/bin/python /usr/local/bin/python2.6. do not use a different name of your fancy for the link. now, if you enter python you'll still have 2.5.2, whereas entering python2.6 will make you feel a tad better. (note: i keep entering all commands with the 'sudo' prefix because for some reason the python installer didn't grant me permissions to write to its directory structure. i suppose you could use chmod and modify the permissions but i'm not familiar with either the syntax or the results and i'm not going to learn it now.)

  • install setuptools: download the egg file for python 2.6 and enter sh setuptools-0.6c9-py2.6.egg. this is why the symbolic link above has to be called 'python2.6' (the setuptools script runs a 'python2.6 exec' command and will complain about a missing 2.6 version if it's not linked with 'python2.6').

  • optional but highly recommended: install ipython. do not download anything. with setuptools installed, you can simply go into your python bin directory (cd /home/yourusername/python/bin) and type ./easy_install IPython. download and install will be automatic.

  • edit the .bashrc file in your home directory so as to add the path to ipython to your environment. simply add PATH=$PATH:/home/yourusername/python/bin to the end of the file. i suppose you could create a symbolic link instead but i haven't tried it.

  • if you use geany for python development, you need to edit one of its configuration files so that the 'run' command executes the proper interpreter: enter sudo gedit /usr/share/geany/filetypes.python and modify the run_cmd line to read: run_cmd=python2.6 "%f" (this will make use of the symbolic link you created earlier).

  • you can now run ipython, develop in a gui ide, and still install packages through aptitude or synaptic without all hell breaking loose. enjoy.
CryingSaul
New Python User
New Python User
 
Posts: 27
Joined: Wed Dec 10, 2008 12:49 am

Re: successfully install python 2.6.1 on ubuntu

Postby Wacky on Wed Jan 21, 2009 11:25 am

Thanks for the write-up, CryingSaul!

I've just nuked my old 2.6 custom install to try your guide, and I have a few comments on it.

For convenience, here's a copy-paste-able line to get all of those packages installed:

Code: Select all
sudo aptitude install build-essential libncursesw5-dev libreadline5-dev \
libssl-dev libgdbm-dev libbz2-dev libc6-dev libsqlite3-dev libdb-dev tk-dev

CryingSaul wrote:
  • download and extract the python 2.6.1 source. from inside the source directory, enter ./configure --prefix=/home/yourusername/python. ignore, of course, the period that precedes this sentence. this will setup python to install into a 'python' directory inside your home directory, far away from anything system-like.

I would personally recommend making it either "--prefix/home/yourusername/python2.6" or "--prefix/home/yourusername/python/2.6", because if you then wish to install 3.0 as well, you don't end up with an ambiguous "/home/yourusername/python" directory that just happens to have 2.6 in it. This is really just a matter of personal taste, though. ;)

  • type sudo make install. i tried to do a sudo make altinstall (after going through the python source readme file), but for some reason i ended up without an executable. so just go through a regular install.

I recommend omitting the sudo, as this will leave you with a directory (and everything in it) belonging to root in your user space, not belonging to you. (I tried it without that, and it worked fine for me on 8.04/Hardy.)

  • create a symbolic link to the 2.6.1 interpreter so that the next step doesn't blow up in your face: sudo ln -s /home/yourusername/python/bin/python /usr/local/bin/python2.6. do not use a different name of your fancy for the link. now, if you enter python you'll still have 2.5.2, whereas entering python2.6 will make you feel a tad better. (note: i keep entering all commands with the 'sudo' prefix because for some reason the python installer didn't grant me permissions to write to its directory structure. i suppose you could use chmod and modify the permissions but i'm not familiar with either the syntax or the results and i'm not going to learn it now.)

It's probably a very, very good idea to only ever run non-system Python versions explicitly, like you suggest. That means using python2.6 when you want 2.6, and python3.0 if you have it installed and want that version. Keeping python reserved for the exclusive use of the system's Python version is likely to avoid headaches in future (as CryingSaul and I have seen ;)).

  • install setuptools: download the egg file for python 2.6 and enter sh setuptools-0.6c9-py2.6.egg. this is why the symbolic link above has to be called 'python2.6' (the setuptools script runs a 'python2.6 exec' command and will complain about a missing 2.6 version if it's not linked with 'python2.6').

  • optional but highly recommended: install ipython. do not download anything. with setuptools installed, you can simply go into your python bin directory (cd /home/yourusername/python/bin) and type ./easy_install IPython. download and install will be automatic.

For reference: you don't have to invoke easy_install that way. Once you've installed setuptools the way CryingSaul described, you can simply type easy_install-2.6 packagename to have it work. Or that worked for me, at least. :P Caveats, caveats...

  • edit the .bashrc file in your home directory so as to add the path to ipython to your environment. simply add PATH=$PATH:/home/yourusername/python/bin to the end of the file. i suppose you could create a symbolic link instead but i haven't tried it.

I think that way is probably the safest, and I'm glad you've put the additional directory after including the existing PATH variable -- I thought of that as I was reading the beginning of your tutorial. :) It nicely ensures that whenever and wherever you type just "python", it will give you the system version. Good idea.

On the whole, an excellent write-up, CryingSaul. Thanks for putting all the effort in, and not giving up. :mrgreen:

I have one minor appendix to add, for people following the above and encountering problems installing the Python Imaging Library (PIL) on Ubuntu 8.04 (Hardy). After successfully installing Python 2.6.1 to ~/python/2.6/, I tried to install PIL. No joy. It spat out the following error:

Code: Select all
_imagingtk.c:20:16: error: tk.h: No such file or directory
_imagingtk.c:23: error: expected ‘)’ before ‘*’ token
_imagingtk.c:31: error: expected specifier-qualifier-list before ‘Tcl_Interp’
_imagingtk.c: In function ‘_tkinit’:
_imagingtk.c:37: error: ‘Tcl_Interp’ undeclared (first use in this function)
_imagingtk.c:37: error: (Each undeclared identifier is reported only once
_imagingtk.c:37: error: for each function it appears in.)
_imagingtk.c:37: error: ‘interp’ undeclared (first use in this function)
_imagingtk.c:45: error: expected expression before ‘)’ token
_imagingtk.c:51: error: ‘TkappObject’ has no member named ‘interp’
_imagingtk.c:55: warning: implicit declaration of function ‘TkImaging_Init’
error: command 'gcc' failed with exit status 1

To get around this and successfully install PIL, I had to install manually instead of using easy_install-2.6, because I had to make the following change on Ubuntu 8.04 (Hardy), even with all the aforementioned system packages installed.

In PIL's setup.py, replace this line:

Code: Select all
TCL_ROOT = None

with this one:

Code: Select all
TCL_ROOT = "/usr/include/tk"

and run python2.6 setup.py install again. All I can say is that it worked for me. ;)
The plus sign (+) is valid within an email address; please do not
write or suggest code that precludes its use, as many use it as a
"label" to filter incoming mail. </crusade> (Eek! Heresy, Imagist! ;))
Wacky
Python Guru
Python Guru
 
Posts: 673
Joined: Fri Aug 29, 2008 10:40 am
Location: EU

Re: successfully install python 2.6.1 on ubuntu

Postby CryingSaul on Wed Jan 21, 2009 1:38 pm

thanks for the comments, wacky. it's comforting to see i haven't made too many blunders. your suggestion for the --prefix is obviously the better way to go if you're planning on installing multiple versions on top of the system version. but after reading all that's changed in 3.0, i'm not going to touch it anytime soon. i only needed 2.6. with our era's definition of "quality components" being what it is, my eee pc is probably going to die anyway before 3.0 becomes widespread :)
CryingSaul
New Python User
New Python User
 
Posts: 27
Joined: Wed Dec 10, 2008 12:49 am

Re: successfully install python 2.6.1 on ubuntu

Postby BlueKitties on Thu Jan 22, 2009 6:51 am

build-essential

Oh, the brutal pain that package has brought me. I tried getting Ubuntu on my laptop, it was my first time with a Linux distro. Everything was going smooth, until I realized I couldn't go online... it was ugly, needless to say (I needed the NDISWRAPPER package.) It took me ages to realize the reason my make commands were failing was because of not having build-essentials.

Anyway, this guide looks promising, I'll probably end up using it before the month is out. Kudos -- this will probably help people who come here through google, too (I can't count the times google has led me to these forums already.)
'les charmes enchanteux de cette sublime science ne se decelent dans toute leur beaute qu'a ceux qui ont le courage de l'approfondir.'
User avatar
BlueKitties
Python Heavy Programmer
Python Heavy Programmer
 
Posts: 242
Joined: Mon Jul 21, 2008 12:09 pm
Location: Jacksonville, TX (USA)

Re: successfully install python 2.6.1 on ubuntu

Postby CryingSaul on Thu Jan 22, 2009 1:50 pm

i've posted a revised tutorial, incorporating wacky's suggestions, on my web site. comments on successes or failures are still welcome.
CryingSaul
New Python User
New Python User
 
Posts: 27
Joined: Wed Dec 10, 2008 12:49 am

Re: successfully install python 2.6.1 on ubuntu

Postby Imagist on Thu Mar 05, 2009 9:57 am

Reviving an ancient thread, but...

I want to install Python 3.0.1 on my newly-purchased Inspiron Mini 9 w/ Dell's version of Ubuntu Hardy. Anyone tried this who's willing to share their gained wisdom on the subject?
I ain't no hollaback girl.
Imagist
Python Heavy Programmer
Python Heavy Programmer
 
Posts: 379
Joined: Tue Mar 25, 2008 7:30 am
Location: Philadelphia

Re: successfully install python 2.6.1 on ubuntu

Postby nilamo on Thu Mar 05, 2009 10:28 am

Does it use special repos? I thought 3.0 has been in the Ubuntu repos for a while now...
As you know, these are open forums, you're able to come and listen to what I have to say."
- President Bush, October 28, 2003, Washington D.C.
nilamo
Ultimate Python Hacker
Ultimate Python Hacker
 
Posts: 1913
Joined: Sun Dec 09, 2007 5:07 pm
Location: The Underground Railroad

Re: successfully install python 2.6.1 on ubuntu

Postby music on Thu Mar 05, 2009 5:27 pm

Python 3.0rc1 is in the repos for Intrepid, but not 3.0.1. Neither is probably in the Hardy repos.

I actually compiled and installed 3.0.1 a couple of days ago. First download the source tarball and extract it. Then go into the directory with files like configure and README in it.

Now install dependencies. this person claims that
Code: Select all
sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libbz2-dev libc6-dev libsqlite3-dev tk-dev g++ gcc
should cover it, but I can't be sure since I already had most dependencies installed.

Next run ./configure. If a module is not being built that it seems should be, then try and figure out what dependency is not satisfied and rerun ./configure until you get the results you want.

Then run "make" followed by "sudo make altinstall" (you don't want to override the system Python).
User avatar
music
Ultimate Python Hacker
Ultimate Python Hacker
 
Posts: 1330
Joined: Wed Jun 27, 2007 4:03 pm
Location: Virginia, USA

Re: successfully install python 2.6.1 on ubuntu

Postby Sneekula on Sat Aug 01, 2009 2:32 pm

Here is a much easier install of Python 2.6.2 on Linux, in my case Ubuntu Intrepid:

Installing Python2.6 on Linux Ubuntu:

Go to http://www.activestate.com/activepython/
and download ActivePython-2.6.2.2-linux-x86.tar.gz via
http://downloads.activestate.com/Active ... x86.tar.gz

Extract to the Desktop

In the terminal change to the proper directory:

cd ~/Desktop/ActivePython-2.6.2.2-linux-x86/

Then run:

sudo ./install.sh

As install directory I entered something easy like:

/home/dell/python/2.6

The installation takes a short time. Now create a symbolic link:

sudo ln -s /home/dell/python/2.6/bin/python2.6 /usr/local/bin/python2.6


Here is the Terminal info:

dell@dell-laptop:~$ cd ~/Desktop/ActivePython-2.6.2.2-linux-x86/
dell@dell-laptop:~/Desktop/ActivePython-2.6.2.2-linux-x86$ sudo ./install.sh
[sudo] password for dell:
Enter directory in which to install ActivePython. Leave blank and
press 'Enter' to use the default [/opt/ActivePython-2.6].
Install directory: /home/dell/python/2.6
()
Installing ActivePython to '/home/dell/python/2.6'...
Relocating dir-dependent files...
Pre-compiling .py files in the standard library...

ActivePython has been successfully installed to:

/home/dell/python/2.6

You can add the following to your .bashrc (or equivalent)
to put python on your PATH:

export PATH=/home/dell/python/2.6/bin:$PATH

The documentation is available here:

/home/dell/python/2.6/doc/python2.6/index.html
web: http://aspn.activestate.com/ASPN/docs/ActivePython

Please send us any feedback you might have or log bugs here:

activepython-feedback@ActiveState.com
http://bugs.activestate.com/ActivePython/

Thank you for using ActivePython.

dell@dell-laptop:~/Desktop/ActivePython-2.6.2.2-linux-x86$ sudo ln -s /home/dell/python/2.6/bin/python2.6 /usr/local/bin/python2.6
dell@dell-laptop:~/Desktop/ActivePython-2.6.2.2-linux-x86$
Babes love a man who uses his Lisp!
User avatar
Sneekula
Python Guru
Python Guru
 
Posts: 744
Joined: Sun May 28, 2006 6:27 am
Location: Detroit

Re: successfully install python 2.6.1 on ubuntu

Postby kid on Mon Aug 24, 2009 5:53 am

I have carried out similar stuff, on RHEL4, through use of the altinstall option to make:

Code: Select all
~# cd /usr/local/src/
/usr/local/src# wget http://www.python.org/ftp/python/2.4.3/Python-2.4.3.tgz
/usr/local/src# tar xvzf Python-2.4.3.tgz
/usr/local/src# cd Python-2.4.3
/usr/local/src/Python-2.4.3# ./configure
/usr/local/src/Python-2.4.3# make
/usr/local/src/Python-2.4.3# make test
/usr/local/src/Python-2.4.3# make altinstall


An then verify the results:

Code: Select all
~# python -V
Python 2.3.4
~# python2.4 -V
Python 2.4.3
~# which python
/usr/bin/python
~# which python2.4
/usr/local/bin/python2.4
~# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin


This approach should work on most distributions, though requires that you have root access.


--
Cheers,
kid
kid
Python Fan
Python Fan
 
Posts: 1
Joined: Mon Aug 24, 2009 5:15 am


Return to Python General

Who is online

Users browsing this forum: No registered users and 1 guest


Sponsored by Dreamlink Web hosting and Traduzioni Rumeno Italiano and ASSP Deluxe for cPanel.