Upgrade python without breaking yum

后端 未结 10 1253
耶瑟儿~
耶瑟儿~ 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:24

    I read a piece with a comment that states the following commands can be run now. I have not tested myself so be careful.

    $ yum install -y epel-release
    $ yum install -y python36
    
    0 讨论(0)
  • 2020-11-29 18:27

    I have written a quick guide on how to install the latest versions of Python 2 and Python 3 on CentOS 6 and CentOS 7. It currently covers Python 2.7.13 and Python 3.6.0:

    # Start by making sure your system is up-to-date:
    yum update
    # Compilers and related tools:
    yum groupinstall -y "development tools"
    # Libraries needed during compilation to enable all features of Python:
    yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
    # If you are on a clean "minimal" install of CentOS you also need the wget tool:
    yum install -y wget
    

    The next steps depend on the version of Python you're installing.

    For Python 2.7.14:

    wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
    tar xf Python-2.7.14.tar.xz
    cd Python-2.7.14
    ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
    make && make altinstall
    
    # Strip the Python 2.7 binary:
    strip /usr/local/lib/libpython2.7.so.1.0
    

    For Python 3.6.3:

    wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
    tar xf Python-3.6.3.tar.xz
    cd Python-3.6.3
    ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
    make && make altinstall
    
    # Strip the Python 3.6 binary:
    strip /usr/local/lib/libpython3.6m.so.1.0
    

    To install Pip:

    # First get the script:
    wget https://bootstrap.pypa.io/get-pip.py
    
    # Then execute it using Python 2.7 and/or Python 3.6:
    python2.7 get-pip.py
    python3.6 get-pip.py
    
    # With pip installed you can now do things like this:
    pip2.7 install [packagename]
    pip2.7 install --upgrade [packagename]
    pip2.7 uninstall [packagename]
    

    You are not supposed to change the system version of Python because it will break the system (as you found out). Installing other versions works fine as long as you leave the original system version alone. This can be accomplished by using a custom prefix (for example /usr/local) when running configure, and using make altinstall (instead of the normal make install) when installing your build of Python.

    Having multiple versions of Python available is usually not a big problem as long as you remember to type the full name including the version number (for example "python2.7" or "pip2.7"). If you do all your Python work from a virtualenv the versioning is handled for you, so make sure you install and use virtualenv!

    0 讨论(0)
  • 2020-11-29 18:27
    ln -s /usr/local/bin/python2.7 /usr/bin/python
    
    0 讨论(0)
  • 2020-11-29 18:29

    If you want to try out rpm packages, you can install binary packages based on the newest Fedora rpms, but recompiled for RHEL6/CentOS6/ScientificLinux-6 on:

    http://www.jur-linux.org/download/el-updates/6/
    

    best regards,

    Florian La Roche

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