Linux – Upgrading Python 2.X on CentOS or RHEL

linuxpython

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!

Best Answer

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.

Related Topic