Upgrade python without breaking yum

后端 未结 10 1252
耶瑟儿~
耶瑟儿~ 2020-11-29 17:28

I recently installed Python 2.7.3 on a CentOS machine by compiling from source. Python 2.7.3 is installed at /opt/python2.7 and when I installed it I just changed /usr/bin/p

相关标签:
10条回答
  • 2020-11-29 18:07

    Daniel's answer is probably the most ideal one as it doesn't involve changing OS files. However, I found myself in a situation where I needed a 3rd party program which invoked python by calling usr/bin/python, but required Python 2.7.16, while the default Python was 2.7.5. That meant I had to make usr/bin/python point to a Python version of 2.7.16 version, which meant that yum wouldn't work.

    What I ended up doing is editing the file /usr/bin/yum and replacing the shebang there to use to the system default Python (in my case, that meant changing #! /usr/bin/python to #! /usr/bin/python2). However, after that running yum gave me an error:

    ImportError: No module named urlgrabber.grabber
    

    I solved that by replacing the shebang in /usr/libexec/urlgrabber-ext-down the same way as in /usr/bin/yum. I.e., #! /usr/bin/python to #! /usr/bin/python2. After that yum worked.

    This is a hack and should be used with care. As mentioned in other comments, modifying OS files should be last resort only.

    0 讨论(0)
  • 2020-11-29 18:16

    Put /opt/python2.7/bin in your PATH environment variable in front of /usr/bin...or just get used to typing python2.7.

    0 讨论(0)
  • 2020-11-29 18:19
    vim `which yum`
    modify #/usr/bin/python to #/usr/bin/python2.4
    
    0 讨论(0)
  • 2020-11-29 18:19

    pythonz, an active fork of pythonbrew, makes this a breeze. You can install a version with:

    # pythonz install 2.7.3
    

    Then set up a symlink with:

    # ln -s /usr/local/pythonz/pythons/CPython-2.7.3/bin/python2.7 /usr/local/bin/python2.7
    # python2.7 --version
    Python 2.7.3
    
    0 讨论(0)
  • 2020-11-29 18:21

    I recommend, instead, updating the path in the associated script(s) (such as /usr/bin/yum) to point at your previous Python as the interpreter.

    Ideally, you want to upgrade yum and its associated scripts so that they are supported by the default Python installed.

    If that is not possible, the above is entirely workable and tested.

    Change:

    #!/usr/bin/python
    

    to whatever the path is of your old version until you can make the above yum improvement.

    Cases where you couldn't do the above are if you have an isolated machine, don't have the time to upgrade rpm manually or can't connect temporarily or permanently to a standard yum repository.

    0 讨论(0)
  • 2020-11-29 18:23

    Alright so for me, the error being fixed is when there are different versions of python installed and yum can't find a certain .so file and throws an exception.
    yum wants 2.7.5 according to the error.

    which python gives me /usr/bin/python
    python --version gives me 2.7.5
    

    The fix for me was append /lib64 to the LD_LIBRARY_PATH environment variable. The relevant content is /lib64/python2.7 and /lib64/python3.6.

    export LD_LIBRARY_PATH=/lib64:$LD_LIBRARY_PATH
    

    Fixed the yum error for me with multiple python versions installed.

    0 讨论(0)
提交回复
热议问题