安装点差失败

时间:2014-07-17 06:03:49

标签: python linux python-2.7 pip yum

我正在使用redhat 5.3

我使用以下命令将python更新为2.7。 (更新前是python 2.4)

# xz -d Python-2.7.6.tar.xz
# tar xvf Python-2.7.6.tar
# cd Python-2.7.6/
# ./configure 
# make && make install

我安装了python-setuptools

# yum install python-setuptools

然后我安装pip打印错误

         ^
SyntaxError: invalid syntax
  File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/__init__.py", line 2
    from .initialise import init, deinit, reinit
         ^
SyntaxError: invalid syntax
  File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/winterm.py", line 2
    from . import win32
         ^
SyntaxError: invalid syntax
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin

Installed /usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg
Processing dependencies for pip

我运行命令pip,它会打印以下错误:

# pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2603, in <module>
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: pip==1.5.6

我尝试卸载它,它告诉我:

[root@linkea-dev-srv1 /]# yum remove pip
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Setting up Remove Process
No Match for argument: pip
Loading mirror speeds from cached hostfile
No Packages marked for removal
You have new mail in /var/spool/mail/root

所以我尝试通过python get-pip.py重新安装pip。 它也有错误。

# python get-pip.py 
Traceback (most recent call last):
  File "get-pip.py", line 17474, in <module>
    main()
  File "get-pip.py", line 17466, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 17406, in bootstrap
    import pip
  File "/tmp/tmpB9jhvw/pip.zip/pip/__init__.py", line 9, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/log.py", line 9, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/__init__.py", line 2, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/initialise.py", line 5, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/ansitowin32.py", line 6, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/winterm.py", line 2, in <module>
  File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/win32.py", line 7, in <module>
  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes

1 个答案:

答案 0 :(得分:8)

在RedHat(包括Fedora / CentOS)上升级Python时应该非常小心,因为绝大多数系统应用程序都依赖于捆绑版本的Python。 yum尤其如此,它依赖于与操作系统捆绑在一起的Python版本。

简而言之 - 如果你在RedHat / CentOS / Fedora上升级Python的版本,yum将无法正常工作

要在这些发行版上安装不同版本的Python,您有两个主要选项。一个是找到已发布rpm的人,下载安装即可;但你可能不得不自己处理依赖。

另一个(更简单的)选项是下载Python的源代码,编译它然后单独安装(使用altinstall)。

您需要先安装以下软件包:

  • yum groupinstall "Development tools"
  • yum install zlib-devel bzip2-devel openssl-devel ncurses-devel

接下来,下载源并将其解压缩。在撰写本文时,最新版本为2.7.8:

  • wget "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.xz"
  • tar xvf Python-2.7.8.xz
  • cd Python-2.7.8

现在,您必须使用以下内容构建Python并将其安装到备用位置:

  • ./configure --prefix=/usr/local
  • make && make altinstall

完成此操作后,您将/usr/local/bin/python2.7可用。接下来,您将要为此版本的Python 安装pip 。为此,首先安装setuptools:

  • wget "https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py"
  • /usr/local/bin/python2.7 ez_setup.py
  • /usr/local/bin/easy_install-2.7 pip

最后一步是确保您可以使用此版本的Python。您可以通过修改shell的环境将/usr/local/bin/添加到$PATH(例如,在$HOME/.bashrc中添加);或者您可以以root身份在/usr/bin/中为这些实用程序创建符号链接。确保为他们提供特定于版本的标签:

  • ln -sf /usr/local/bin/python2.7 /usr/bin/python2.7
  • ln -sf /usr/local/bin/pip /usr/local/bin/pip2.7

这会将您的默认Python保留为系统的版本(推荐),然后在需要时为您提供使用2.7的选项。