使用easy_install安装pip

28
我没有root访问权限,想要从头安装Python。所以我下载了Python源代码并编译了它。接下来我想安装pip,但是当我运行python get-pip.py时遇到了这个错误:ImportError: cannot import name HTTPSHandler
由于我没有root访问权限,无法安装所需的内容。因此我认为也许可以使用easy_install安装pip,于是我安装了setuptools,它包含easy_install。但是当我运行easy_install pip时遇到了这个错误:
Searching for pip
Reading https://pypi.python.org/simple/pip/
Download error on https://pypi.python.org/simple/pip/: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: unknown url type: https -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

现在该怎么安装pip呢?我真的快疯了!

编辑:我不能使用virutalenv


为什么不能使用virtualenv? - ErlVolton
请查看此帖子: https://dev59.com/jGIj5IYBdhLWcg3wwHlr - Social Outcast
6个回答

20
尝试使用以下命令安装pip: "easy_install-2.7 -U --user pip"
**another important info** 

在Ubuntu、Debian或Linux Mint上安装pip:

$ sudo apt-get install python-pip
在 Fedora 上安装 pip:

要在 Fedora 上安装 pip:

$ sudo yum install python-pip

要在CentOS上安装pip,首先需要启用EPEL软件仓库,然后运行以下命令:

$ sudo yum install python-pip

在Archlinux上安装pip:

$ sudo pacman -S python-pip

3
我没有 root 权限! - Jack Twain
您可以在SUSE上使用sudo zypper install python-pip进行安装。 - mebada

8

虽然这并不是针对原问题的直接回答,但如果你不幸正在尝试在CentOS6上使用easy_install安装pip,那么我希望这可以帮到你。

过去这种方法可以成功,但现在会出现以下错误:

$ docker run -ti centos:6 bash -c 'yum install -y python-setuptools && easy_install pip'
...
Installed:
  python-setuptools.noarch 0:0.6.10-3.el6                                                                                                                       

Complete!
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

我猜测http://pypi.python.org已经开始严格要求使用https。 如果你进行以下小技巧,那么easy_install pip将会起作用。 sed --in-place 's#http://pypi.python.org#https://pypi.python.org#g' /usr/lib/python2.6/site-packages/setuptools/command/easy_install.py


现在情况变得更糟了,CentOS 6 用户需要使用 pip 9.0.3。最新版本的 pip(pip 10)会破坏 CentOS 6.9 的兼容性,这似乎很疯狂,因为 CentOS 6 仍然得到支持,还有大量用户并且 Python 已经默认安装在 CentOS 上。例如:docker run -ti centos:6 bash -c 'yum install -y python-setuptools && easy_install pip==9.0.3 && pip install restnavigator'。 - jamshid

5

对于那些没有root权限的用户,这是我解决问题的方法。

  1. Download Python (Gzipped source tarball).

  2. Unzip and cd to the Python source directory.

  3. Configure with the "--with-ensurepip=install" flag, e.g.,

    ./configure --prefix=[your-specified-dir] --with-zlib-dir=/usr/lib64 --with-ensurepip=install
    
  4. make & make install

  5. Now you should have a working but out-dated pip. To get the latest pip, download the get-pip.py file and run python get-pip.py

现在您应该拥有最新的pip。享受吧。 :)


-1

Virtualenv来拯救!它自带pip,不需要root访问权限,并允许您拥有不同的环境,每个环境都有自己的python、pip和模块副本。安装文档列出了几种安装方法,您需要选择最后一种叫做“从源代码本地使用”。请还要查看virtualenvwrapper,这只是一组shell脚本,使得使用virtualenv更加容易。Google会提供关于这两个工具的丰富教程。


2
为什么负数如此受欢迎? - ErlVolton

-1

这个问题也困扰了我很久,但是以下方法对我有效:

python3 get-pip.py


-1

pip安装涉及到您的Python版本,请确认一下。在我的情况下,我使用的是Python3,所以我使用以下命令进行安装,并且它可以正常工作。让我们试试这个:

我正在使用MacOS。

$ python3 get-pip.py


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接