通过“setup.py 开发”安装失败 - pip 有效



我的python包footools需要html5lib通过setup.py中的install_requires

setup.py 开发失败

通过setup.py develop安装失败:

cd src/footools/
python setup.py develop
Processing dependencies for footools==2016.205
Searching for html5lib==0.9999999
Reading https://source.example.com/pypi/simple/html5lib/
Download error on https://source.example.com/pypi/simple/html5lib/: 
   [Errno 185090050] _ssl.c:354: error:0B084002:x509 
   certificate routines:X509_load_cert_crl_file:system lib -- 
   Some packages may not be found!
Couldn't find index page for 'html5lib' (maybe misspelled?)

点子作品

但是直接下载有效:

bar@workdevel123:~/src/footools> pip install html5lib==0.9999999
/home/bar/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: 
InsecurePlatformWarning: A true SSLContext object is not available. 
This prevents urllib3 from configuring SSL appropriately
and may cause certain SSL connections to fail. 
For more information, see 
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Collecting html5lib==0.9999999
/home/bar/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: 
    InsecurePlatformWarning: A true SSLContext object is not available. 
    This prevents urllib3 from configuring SSL appropriately and
    may cause certain SSL connections to fail. 
    For more information,
    see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://source.example.com/pypi/packages/html5lib-0.9999999.tar.gz
Requirement already satisfied (use --upgrade to upgrade):
six in /usr/lib/python2.7/site-packages (from html5lib==0.9999999)
Installing collected packages: html5lib
  Running setup.py install for html5lib
Successfully installed html5lib-0.9999999

问题

这两种方法有什么区别?

它们为什么不同?

在 python 中安装依赖项的正确方法是什么?

setup.py

setup.py并不特别:

import setuptools
setuptools.setup(
    name='foo',
    version='2016.210',
    long_description=open('README.txt').read(),
    packages=setuptools.find_packages(),
    install_requires=[
        # about twenty packages before this line
        'html5lib==0.9999999'
],
    include_package_data=True,
    entry_points={
        'console_scripts': [
            'foo=foo.utils.bar:main',
        ],
    },
)

python setup.py develop,或setuptools通常使用easy_install来满足依赖关系,而依赖关系又使用urllib2pip使用requests。请参阅此处了解 easy_install vs pip.
pip更现代,具有卸载软件包的功能,并符合PEP 438 - 过渡到PyPI上的发布文件托管。你可以用pip install -e src/footools/实现与python setup.py develop相同的目的,注意项目路径是否在当前目录使用中,./footools

requests 软件包将 CA 证书捆绑在软件包本身中,python -c 'import pip;print(pip.download.requests.certs.where())' .

setuptools使用系统安装的 CA 证书python -c 'from setuptools import ssl_support;print(ssl_support.cert_paths)'

您必须使用 Ubuntu update-ca-certificates 等工具更新系统安装的 CA 证书,以自动更新 CA 证书或从 https://curl.haxx.se/docs/caextract.html 下载并安装到 setuptools 显示的路径之一中,或者将setuptools.ssl_support.cert_paths设置为空序列,如 []pip install certifi执行 .
调用 setuptools.ssl_support.find_ca_bundle()将显示 CA 证书的位置。

setuptools是Python distutils(适用于Python 2.6及更高版本)的增强功能集合,允许开发人员更轻松地构建和分发Python包,尤其是

那些依赖于其他包的包。

因此,除其他内容外,您还可以创建可以上传到 Pypi 的包,然后使用 pip 安装(因此分发您的模块)。

也就是说,它们实际上在安装部分不应该有那么不同。您正在运行develop模式,因此也许您必须稍微摆弄一下目录或修复授权错误。

在开发模式下,项目被部署到暂存区域(在某种程度上类似于虚拟环境的过程)

部署的完成方式是,对项目源的更改立即在暂存区域中可用,而无需在每次更改后运行生成或安装步骤。

这意味着所有内容都将可用于该python解释器。以后可以取消暂存。

我注意到html5lib是从不同的地方获取的:一种情况下/pypi/simple/,另一种情况下/pypi/packages/

dependency_links 在满足依赖项时要搜索的命名 URL 的字符串列表。如果需要安装setup_requires或tests_require指定的软件包,将使用这些链接。

回到问题,我认为这很可能是 ssl 问题,因为在 pip 中它处理得很优雅(即,很好的警告和某种解决方法),但设置工具不会发生同样的情况。如果请求中存在未处理的错误,则Couldn't find index page for 'html5lib'可能是因为此原因。

这两种方法有什么区别?

作为

用户,除了不同的用户界面之外,没有什么特别重要的。它们是风景秀丽的历史火车上的两站。一路上还有其他人。

它们为什么不同?

过去,Python没有附带包管理系统。第三方解决方案填补了这一空白。它们是由不同的人在不同的时刻设计的。如果你看看其他编程语言,你有时会看到类似的故事;有时你会看到更快乐的故事;有时更悲惨。

在 python 中安装依赖项的正确方法是什么?

这两种方法在技术上都是正确的。Pip 是更现代的方法,根据我的经验,它更受欢迎,使用起来更方便。从Python 3.4及更高版本开始,Pip已被包含在CPython发行版中,并且是官方的"首选"。所以你可以看到风向。

最新更新