9

I just tried to upgrade the Python installation on my CentOS machine. After few times of failure, I did yum remove python.

Then problems started to happen. yum found about 300 dependencies on the machine, after I confirmed the operation, almost every command and utility became unavailable, including ls, wget, yum itself... I got no choice but reboot the instance (I am so thankful it's just a dev machine.)

I am wondering if removing python is so harmful, is there any way to remove python gracefully?

shihpeng
  • 233
  • 4
    There is no way to remove "system" python gracefully, because, as you have discovered, it is needed by the system and many applications. What you need to do is figure out how to install alternative versions of python, while keeping the system version. There are plenty of questions on that around. – juanchopanza Oct 01 '14 at 06:18

1 Answers1

11

Python is required by many of the Linux distributions. Many system utilities the distro providers combine (both GUI based and not), are programmed in Python.

The version of python the system utilities are programmed in I will call the "main" python. For Ubuntu 12.04 e.g. this is 2.7.3, the version that you get when invoking python on a freshly installed system.

Because of the system utilities that are written in python it is impossible to remove the main python without breaking the system. It even takes a lot of care to update the main python with a later version in the same major.minor series, as you need to take care of compiling it with the same configuration specs as the main python. This is needed to get the correct search paths for the libraries that the main python uses, which is often not exactly what a .configure without options would get you, when you download python to do a python compilation from source.

Installing a different version from the major.minor version the system uses (i.e. the main python) normally is not a problem. I.e. you can compile a 2.6 or 3.4 python and install it without a problem, as this is installed next to the main (2.7.X) python. Sometimes a distro provides these different major.minor packages, but they might not be the latest bug-release version in that series.

The problems start when you want to use the latest in the main python series (e.g. 2.7.8 on a system with main python version is 2.7.3). I recommend not trying to replace the main python, but instead to compile and install the 2.7.8 in a separate location (mine is in /opt/python/2.7.8). This will keep you on the security fix schedule of your distribution and guarantees someone else tests compatibility of the python libraries and against that version (as used by system utilities!).

For any development using that version of python, use virtualenv, (or virtualenvwrapper) and setup a 2.7.8 environment using:

virtualenv -p /opt/python/2.7.8/bin/python /tmp/test
source /tmp/test/bin/activate

(the second line assumes you are using bash)

Anthon
  • 79,293
  • Thanks for your excellent explanation. I learned so much from your answer:) – shihpeng Oct 02 '14 at 07:54
  • 1
    @shihpeng Your welcome, and thanks for the feedback. It motivated me to review the answer and make it somewhat more readable (extra comma's etc). Nothing significant that you don't know already, but hopefully making it more helpful for future visitors. – Anthon Oct 02 '14 at 08:24