我最近通过从源代码编译在一台CentOS机器上安装了Python2.7.3。Python 2.7.3安装在/opt/python2.7上,当我安装它时,我只是将/usr/bin/python改为指向新版本。这显然是错误的,因为当我这样做的时候,它弄坏了美味。我会得到以下内容。
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.3 (default, May 15 2012, 17:45:42)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
我将/usr/bin/python更改为指向python 2.6.6,但现在2.6.6是python的默认版本。你知道怎么解决这个问题吗?
发布于 2012-06-26 04:30:09
我写了一个关于如何在CentOS 6和CentOS 7上安装Python2和Python3的最新版本的quick guide。目前它涵盖了Python2.7.13和Python3.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
接下来的步骤取决于您要安装的Python版本。
对于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
对于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
要安装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]
您不应该更改Python的系统版本,因为它会破坏系统(正如您发现的那样)。只要不安装原始系统版本,安装其他版本就可以正常工作。这可以通过在运行configure时使用自定义前缀(例如/usr/local
),以及在安装Python时使用make altinstall
(而不是普通的make install
)来实现。
有多个版本的Python通常不是一个大问题,只要您记得输入包括版本号的全名(例如"python2.7“或"pip2.7")。如果您在一个virtualenv上执行所有的Python工作,那么版本控制将为您处理,所以请确保您安装并使用了virtualenv!
发布于 2013-05-15 12:59:21
vim `which yum`
modify #/usr/bin/python to #/usr/bin/python2.4
发布于 2012-05-17 02:34:31
将/opt/python2.7/bin
放在您的PATH
环境变量中,放在/usr/bin
...or前面,只需习惯输入python2.7
即可。
https://stackoverflow.com/questions/10624511
复制相似问题