Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I hate to play the annoying dull person who doesn't have a clue what he is talking about. But, unfortunately, that's me as far as linux is concerned...

I'm doing some file manipulations in python that use the zipfile module. The version of python currently installed is 2.4.3, but the zipfile module utilizes 'with' statements, which I think came out in version 2.5 (I'm also going to need to use the tarfile module; although I haven't tested it, I imagine I'll run into the same problem).

My current plan of action is to figure out how to upgrade the python installation. But, knowing absolutely nothing about linux and very little about python, I don't even know where to start. I look at some similar posts, which mentioned installing it in another directory. I didn't install it in the first place though. I don't even know how to install stuff in linux...

Any help would be greatly appreciated! Also, if there's a better way than trying to update python, I'm totally open to suggestions. Just remember: my linux intelligence is about equivalent to that of a four-year-old. Thanks!

share|improve this question

migrated from May 24 '12 at 16:43

This question came from our site for professional and enthusiast programmers.

I am not sure this is the right place for this question, but in any case, your question should probably include what Linux distribution/version you are using. Most distributions these days will provide a GUI to upgrade your software without the need for command line commands .. (that sounds redundant :) – Levon May 24 '12 at 14:48
zipfile, tarfile are in stdlib. So the version that comes with Python 2.4 must work as is i.e., it doesn't use with statement. If you need a newer version of Python for some other reason then you could use your distribution packages to install it (as an addition, not a replacement) e.g., sudo apt-get install python3.2. Don't touch your default Python installation it might break things. – J.F. Sebastian May 24 '12 at 15:20

The easiest way to upgrade Python on Linux is to have someone else do it for you; your distribution often has many people who package upgrades specifically for that distribution. Before you roll up your sleeves and get into it, see if they have already done the work.

Basically, this means learning what type of package manager your distribution uses, and then seeing if the next release is available. Weaknesses to this technique exist:

  1. Your distribution release might be old and updates are no longer available.
  2. Your distribution might value stability over cutting-edge, and has not yet decided the next release is stable enough (or adequately tested).
  3. Your distribution might not have packaged the needed modules, so you must install them yourself.

For my distribution, rpm is the package manager, and yum is the command line front-end. To check if an update exists for a package with yum, I type

yum check-updates <package name>

and to update something I type

yum update <package name>

Whatever your outcome is with respect to your Python module, you should learn a bit about your package manager and how to use it to avoid the rush of needing to learn it at a critical juncture.

In the event that you do not find the right version packaged for you, sometimes a search on Google will yield a person who packaged the right version for your distribution, even though your distribution hasn't done so yet. If so, and if you trust the other person to not be doing something malicious, then you can typically install their package.

If no prepackaged version exists, then you are stuck and need to read the "how to install" pages of the particular item, and for Python, it closely reflects Maxime's "the hard way", which might sound intimidating, but after you do it a few times, you realize it isn't really that hard.

Keep in mind that software installed outside of the package manager's knowledge probably will never be known to the package manager, so future use of the package manager with respect to that software will probably need to be handled specially, to prevent the package manager from doing something that makes sense if your version of Python isn't installed.

share|improve this answer


just work with zip commands directly, instead of using the old zip module:

import subprocess'unzip <path to your file>')

or alternatively, use subprocess.Popen.

And After submitting my answer, I would like to title this part:


Guessing from the Python version you are using a Red Hat 5 or CentOS 5.

Here is how it is looking on my Red Hat 5.8 at work:

oz@server ~ $ /usr/bin/python                                            
Python 2.4.3 (#1, Dec 22 2011, 12:12:01) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('/etc/redhat-release')                                             
>>> f.readlines()
['Red Hat Enterprise Linux Server release 5.8 (Tikanga)\n']

Most other Ubuntu version and Debian have newer Python version.

Anyway, upgrading Python should work like this:

  1. First you need to know the admin password (root in Linux world).
  2. type 'su' to change to root - WATCH OUT HERE, this is a dangerous situations. Being ROOT is dangerous.
  3. type:
yum groupinstall "development tools" -y     
yum install readline-devel openssl-devel gmp-devel ncurses-devel gdbm-devel \
glib-devel expat-devel libGL-devel tk tix gcc-c++ \ 
libX11-devel glibc-devel bzip2 tar tcl-devel tk-devel pkgconfig \
tix-devel bzip2-devel sqlite-devel autoconf db4-devel libffi-devel \
valgrind-devel -y    
mkdir tmp  
cd tmp  
tar xvfz Python-2.7.5.tgz  
cd Python-2.7.5

THIS is important otherwise you will erase your system PYTHON !!! you don't want to do that is, because many system components depend on Python.

./configure --prefix=/opt/python2.7 --enable-shared

Noe, compile the software itself:


Then install it:

make altinstall

Don't miss the --prefix=/opt ./configure --prefix=/opt/python2.7

Finally, you need to set your PATH variable to include the python where Python was installed.

export PATH=$PATH:/opt/python2.7/bin/

To make that permanent, edit your .bashrc, and add the above line!

Good luck and welcome to Linux :-)

share|improve this answer

Not sure why there's so much resistance to just building Python from source, because it's really quite simple:

$ tar jxf Python-2.7.3.tar.bz2   # unpack the source tarball
$ cd Python-2.7.3                # cd into the source directory
$ ./configure --prefix=$HOME     # configure for your system
$ make                           # build everything
$ make install                   # install (in $HOME/bin, $HOME/share, etc )

If you are nervous about doing the install step, first do make DESTDIR=/tmp/foo install and install everything in /tmp/foo. Inspect that directory tree, then rm -rf /tmp/foo (Unless you had important files in /tmp/foo before you started the procedure, of course!)

If you get errors, then there will be some work to do, but chances are very good that the build will work without errors.

Once you've done this, you should be able to run $HOME/bin/python

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.