本文介绍了pip可以搜索软件包,但安装失败并出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有本地pypi服务器,我在其中上传了cffi程序包.

I have local pypi server, where I uploaded cffi package.

当我尝试搜索时,它会返回包裹.

When I try to search, it return the package.

$ pip search -i https://localhost --trusted-host localhost cffi
cffi (1.11.4)  - 1.11.4

但是尝试安装时,它会显示错误.

But when try to install, it gives error.

$ pip install -i https://localhost  --trusted-host localhost cffi==1.11.4
Collecting cffi==1.11.4
  Could not find a version that satisfies the requirement cffi==1.11.4 (from versions: )
No matching distribution found for cffi==1.11.4

我正在apache网络服务器下运行pypi服务器,以处理centos上的https请求.

I am running pypi server under apache webserver to handle https requests on centos.

我检查apache日志/var/log/httpd/ssl_access_log中的install命令.它的返回值200GET Call.

I check the apache log /var/log/httpd/ssl_access_log, for install command. Its return 200 for GET Call.

127.0.0.1 - - [25/Jan/2018:16:46:23 +0000] "GET /cffi/ HTTP/1.1" 303 -
127.0.0.1 - - [25/Jan/2018:16:46:23 +0000] "GET /simple/cffi/ HTTP/1.1" 200 339

我再次检查日志.对于celery,它起作用,之后,对于cffi,它失败.

I check the log again. For celery it works, after that for cffi it fails.

127.0.0.1 - - [25/Jan/2018:16:50:58 +0000] "GET /celery/ HTTP/1.1" 303 -
127.0.0.1 - - [25/Jan/2018:16:50:58 +0000] "GET /simple/celery/ HTTP/1.1" 200 321
127.0.0.1 - - [25/Jan/2018:16:50:58 +0000] "GET /packages/celery-4.0.2-py2.py3-none-any.whl HTTP/1.1" 200 396437
127.0.0.1 - - [25/Jan/2018:16:50:59 +0000] "GET /cffi/ HTTP/1.1" 303 -
127.0.0.1 - - [25/Jan/2018:16:50:59 +0000] "GET /simple/cffi/ HTTP/1.1" 200 339

问题是,对于cffi,它无法重定向到/packages/cffi-1.11.4-cp35-cp35m-manylinux1_x86_64.whl.在celery中,它在GET /simple/celery/之后进入/packages/celery*.

The problem is, for cffi its not redirect to /packages/cffi-1.11.4-cp35-cp35m-manylinux1_x86_64.whl. While in celery its goes to /packages/celery* after GET /simple/celery/.

我尝试curl,检查这两个程序包之间的响应是否有变化,但是没有区别.

I tried to curl, to check if there is change in response between these 2 packages, but there is not difference.

$ curl -k https://localhost/simple/celery/ -i
HTTP/1.1 200 OK
Date: Thu, 25 Jan 2018 16:59:27 GMT
Server: Apache/2.2.15 (CentOS)
Content-Length: 321
Connection: close
Content-Type: text/html; charset=UTF-8

    <html>
        <head>
            <title>Links for celery</title>
        </head>
        <body>
            <h1>Links for celery</h1>
                 <a href="/packages/celery-4.0.2-py2.py3-none-any.whl#md5=3ff97b53107b491baeb42f662be14a06">celery-4.0.2-py2.py3-none-any.whl</a><br>
        </body>
    </html>
$ curl -k https://localhost/simple/cffi/ -i
HTTP/1.1 200 OK
Date: Thu, 25 Jan 2018 16:59:29 GMT
Server: Apache/2.2.15 (CentOS)
Content-Length: 339
Connection: close
Content-Type: text/html; charset=UTF-8

    <html>
        <head>
            <title>Links for cffi</title>
        </head>
        <body>
            <h1>Links for cffi</h1>
                 <a href="/packages/cffi-1.11.4-cp35-cp35m-manylinux1_x86_64.whl#md5=c9478cf605b4eb2755fa322cc2bf3ddf">cffi-1.11.4-cp35-cp35m-manylinux1_x86_64.whl</a><br>
        </body>
    </html>

推荐答案

遇到此问题时,两个最常见的问题是平台不匹配或python版本不匹配.

Two most common problems when facing this issue are either platform mismatch or python version mismatch.

检查默认的pip所指的python版本-是python3.5pip吗?

Check what python version your default pip refers to - is it the python3.5's pip?

$ pip -V | grep -o "(.*)"

将为您提供信息.如果默认的pip引用了其他一些python版本,请直接使用pip3.5调用python3.5pip:

will give you the info. If default pip refers to some other python version, invoke the python3.5's pip directly with pip3.5:

$ pip3.5 install -i https://localhost  --trusted-host localhost cffi==1.11.4

平台检查

尝试显式下载manylinux1_x86_64平台的cffi软件包-车轮会下载吗?

platform check

Try explicitly downloading the cffi package for the manylinux1_x86_64 platform - will the wheel download?

$ pip download cffi --only-binary=:all: --platform manylinux1_x86_64 -i https://localhost --trusted-host localhost

如果下载成功,则说明目标计算机上的平台不匹配.检查pip可识别的平台:

If the download succeeds, you have a platform mismatch on your target machine. Check what platform is recognized by pip:

$ python3.5 -c "import pip; print(pip.pep425tags.get_platform())"

ABI检查

一个不太常见的问题是ABI不匹配:您可以使用以下方法检查平台的ABI

ABI check

A less common problem is the ABI mismatch: you can check your platform's ABI with

$ python3.5 -c "import pip; print(pip.pep425tags.get_abi_tag())"

此字符串应与平台标记之前的车轮名称中的前缀匹配,因此,在您的情况下,您的ABI应该为cp35m.

This string should match the prefix in the wheel name that comes before the platform tag, so in your case, your ABI should be cp35m.

如果获得macosx_10_13_x86_64平台标签,则意味着您具有MacOS High Sierra.在本地PyPI服务器上,您已经上传了只能安装在linux上的cffi滚轮(manylinux滚轮).您将无法在MacOS High Sierra上安装它.事实是,cffi程序包附带了部分用C编写并仅针对目标平台进行编译的代码.您可以通过以下三种方式解决此问题:

If you get the macosx_10_13_x86_64 platform tag, this means you have MacOS High Sierra. On your local PyPI server, you have uploaded the cffi wheel that can be installed on linux only (manylinux wheel). You won't be able to install it on MacOS High Sierra. The thing is, cffi package ships code partly written in C and compiled for the target platform only. You have three possibilities to solve this:

  1. 最简单的解决方案:下载 macosx_10_13_x86_64滚轮,并将其与manylinux1滚轮一起上传到本地服务器.现在,Linux客户端将在运行pip install cffi时获得为linux编译的转轮,而您将为MacOS编译出转轮.
  2. "DIY"解决方案:下载从PyPI 下载tar安装程序,并将其与manylinux1滚轮一起上传到本地服务器.现在,Linux客户端将获得编译轮,而MacOS和Windows客户端将获得源tar,它们将被迫在本地编译所包含的C代码-如果操作系统未提供正确的工具,则安装将失败.
  3. 配置本地服务器以代理PyPI:如果请求了一个程序包,但在本地服务器上找不到该程序,它将请求传递给pypi.python.org;如果在公共存储库中找到了该程序包,则将其下载并通过本地服务器,就像在本地服务器中找到的一样.但是,不确定服务器是否支持此功能.我们使用devpi足以告诉您的索引它的基数中应该包含root/pypi:devpi index -m user/index bases=root/pypi.
  1. The simplest solution: download the macosx_10_13_x86_64 wheel from PyPI and upload it to your local server alongside the manylinux1 wheel. Now the linux client will get the wheel compiled for linux and you will get the wheel compiled for MacOS when running pip install cffi.
  2. The "DIY" solution: download the source tar installer from PyPI and upload it to your local server alongside the manylinux1 wheel. Now the linux client will get the compiled wheel and MacOS and Windows clients will get the source tar, where they are forced to compile the contained C code locally - if the OS does not provide the right tools, the installation will fail.
  3. Configure the local server to proxy the PyPI: if a package is requested, but not found on your local server, it passes the request through to the pypi.python.org and if the package is found in the public repository, it is downloaded and passed through your local server as if was found there. Not sure, however, if your server supports this feature. We use devpi where it is enough to tell your index that it should have root/pypi among its bases: devpi index -m user/index bases=root/pypi.

请注意,这些解决方案并不互相排斥:您可以将1与2结合使用(Linux客户端将获得manylinux1轮子,High Sierra将获得macos_10_13轮子,其余的将获得源tar),甚至是1、2和3全部一起.这完全取决于您要/需要/可以在本地服务器上进行上传和维护的内容.

Note that these solutions are not mutually excluding: you can combine 1 with 2 (linux clients will get manylinux1 wheels, High Sierra gets macos_10_13 wheel, the rest get the source tar) and even 1, 2 and 3 alltogether. It all depends on what you want/need/can to upload and maintain on your local server.

这篇关于pip可以搜索软件包,但安装失败并出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:56