简体   繁体   English

安装点差失败

[英]Install pip failed

i am using redhat 5.3 我正在使用redhat 5.3

I using following command to update python to 2.7. 我使用以下命令将python更新为2.7。 (it was python 2.4 before update) (更新前是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

And I Install the python-setuptools 我安装了python-setuptools

# yum install python-setuptools

Then I install the pip print the error 然后我安装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

And I run the command pip , it print following errors: 我运行命令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

And I try to uninstall that, it tell me that: 我尝试卸载它,它告诉我:

[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

So I try to reinstall pip by python get-pip.py. 所以我尝试通过python get-pip.py重新安装pip。 It also has error. 它也有错误。

# 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

You should be very careful when upgrading Python on RedHat (including Fedora/CentOS) because a large majority of the system applications rely on the bundled version of Python. 在RedHat(包括Fedora / CentOS)上升级Python时应该非常小心,因为绝大多数系统应用程序都依赖于捆绑版本的Python。 This is especially true of yum , which relies on the version of Python that comes bundled with the operating system. yum尤其如此,它依赖于与操作系统捆绑在一起的Python版本。

In short - if you upgrade the version of Python on RedHat/CentOS/Fedora, yum will not work correctly . 简而言之 - 如果你在RedHat / CentOS / Fedora上升级Python的版本,yum将无法正常工作

To install a different version of Python on these distributions, you have two main options. 要在这些发行版上安装不同版本的Python,您有两个主要选项。 One is to find someone that has released a rpm, download an install that; 一个是找到已发布rpm的人,下载安装即可; but you may have to deal with dependencies on your own. 但您可能必须自己处理依赖项。

The other (simpler) option is to download the source of Python, compile it and then install it separately (using altinstall ). 另一个(更简单的)选项是下载Python的源代码,编译它然后单独安装(使用altinstall )。

You'll need to install the following packages first: 您需要先安装以下软件包:

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

Next, download the source and extract it. 接下来,下载源并将其解压缩。 As of this writing, the latest version is 2.7.8: 在撰写本文时,最新版本为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

Now you have to build and install Python to an alternate location, with the following: 现在,您必须使用以下内容构建Python并将其安装到备用位置:

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

Once this is done, you'll have /usr/local/bin/python2.7 available to you. 完成后,您将获得/usr/local/bin/python2.7 Next, you'll want to install pip for this version of Python . 接下来,您将要为此版本的Python安装pip。 To do that, first install setuptools: 为此,首先安装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

The final step is to make sure that this version of Python is available to you. 最后一步是确保您可以使用此版本的Python。 You can add /usr/local/bin/ to your $PATH by modifying your shell's environment (for example, adding it in $HOME/.bashrc ); 您可以通过修改shell的环境将/usr/local/bin/$PATH (例如,在$HOME/.bashrc添加它); or you can as root create symbolic links in /usr/bin/ to these utilities. 或者您可以以root身份在/usr/bin/为这些实用程序创建符号链接。 Make sure you give them version-specific tags: 确保为其提供特定于版本的标记:

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

This will keep your default Python to the system's version (recommended), and then give you the option to use 2.7 when needed. 这将使您的默认Python保持系统版本(推荐),然后在需要时为您提供使用2.7的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM