Ubuntu – I changed the Python version – but it didn’t “take” everywhere

python

Free Ubuntu-ers. I have a strange problem which I've spent a while trying to debug, and later I searched fairly thoroughly for data on it, without any luck.

I have a fairly new server running Lucid Lynx and I'm attempting to switch the default Python version to 2.7. I've tested all the apps that I'm running and they seem to run well on 2.7 – and it's not a mission-critical server, so I can fail and back out if I like.

I did my homework, installed 2.7, changed the soft links in /usr/bin, and edited my /usr/share/python/debian_defaults to make the default-version python2.7. Then I tried "python" from the command line for "root" and for "some random user account" and got python 2.7 and dusted my hands off.

This was a couple of months ago, and all has worked fine until today…

I tried to run a Python daemon – but it kept failing mysteriously. I tracked it down to a package that wasn't installed – but it was…

After some debugging, I discovered that in fact when I run a Python script as a daemon, it's running Python 2.6.5 – but if I run the same script from the command line, it's running Python 2.7.2 – and I of course haven't installed the new library for Python 2.6. (I'm using the Python daemon library to launch the script as a daemon…)

But my scripts all start with #!/usr/local/bin/python, the version I recently installed, and /usr/local/bin/python --version returns 2.7.2. In fact, I changed the #! line to explicitly point to python 2.7 and it still fails in exactly the same way.

Later, I discovered if I ran the program in pdb, the python debugger, I also get 2.6 as the version.

I think the key is that neither pdb nor the daemon runner pay any attention to the #! line – but I can't get any further than that.

Your kind help is gratefully solicited.

EDIT: Some good suggestions below – if my Stackoverflow karma reached here, I'd upvote them – but no good results (see comments below). Resolution: dump Python 2.6.

Best Answer

Try sudo update-alternatives --config python

Ubuntu/Debian has an alternatives system that it uses in the case that there are multiple programs that do the same thing. See man 8 update-alternatives for more information.

Related Question