python - 忽略 ssl 证书以便于安装 python

标签 python ssl pip dependencies easy-install

我的库设置为

setup.py

from setuptools import setup

setup(
    setup_requires=['pbr>=0.11.0'],
    pbr=True
)

setup.cfg

[metadata]
name = MyLib

[options]
zip_safe = False
include_package_data = True
install_requires =
    cython
    pyrex
    pymssql
    elementtree
    bleach
    BeautifulSoup4
    pytz
    MySQL_python
    retry
    elementtree
    Pyrex
dependency_links =
    https://pypi.mydomain.com/packages/

[files]
packages =
    MyLib
    MyLib.package1
    MyLib.package1.new1

[tool:wheel]
universal = 1

[flake8]
exclude =
    venv,
    .tox,
    .git,
    __pycache__,
    *.pyc,
    *.egg-info,
    .cache,
    .eggs,
max-line-length = 80

[tool:pytest]
testpaths=MyLib/tests
ignore=
    .tox
    .cache
    docs
    config.py
    venv

[coverage:run]
omit=
    MyLib/config.py

我在我的应用程序 requirements.txt 中使用这个 MyLib

myapp/requirements.txt ... ... MyLib==1.2.3 ... ...

当我安装时,使用 /usr/local/pyenv/versions/myapp/bin/pip install -i https://pypi.mydomain.com --trusted-host pypi.mydomain.com -r/opt/school/apps/myapp/requirements.txt,它被重定向到 pypi.python.org。然后我了解到 easy_install 正在使用另一个配置作为 ~/.pydistutils.cfg。我添加为

~/.pydistutils.cfg

[easy_install]
index_url=https://pypi.mydomain.com/
find_links = https://pypi.mydomain.com/simple/
allow_hosts = pypi.mydomain.com

现在它没有重定向到 pypi.python.org 但它给出了 SSL 错误。

/usr/local/pyenv/versions/myapp/bin/pip install -i https://pypi.mydomain.com --trusted-host pypi.mydomain.com -r /opt/school/apps/myapp/requirements.txt
Requirement already satisfied: appdirs==1.4.3 in /usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages (from -r /opt/school/apps/myapp/requirements.txt (line 1))
Requirement already satisfied: beautifulsoup4 in /usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages (from -r /opt/school/apps/myapp/requirements.txt (line 2))
Requirement already satisfied: bleach==2.0.0 in /usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages (from -r /opt/school/apps/myapp/requirements.txt (line 3))
Requirement already satisfied: click==6.7 in /usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages (from -r /opt/school/apps/myapp/requirements.txt (line 4))
Collecting MyLib==1.2.3 (from -r /opt/school/apps/myapp/requirements.txt (line 5))
  Downloading https://pypi.mydomain.com/packages/MyLib-1.2.3.tar.gz (221kB)
    100% |████████████████████████████████| 225kB 31.8MB/s
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.mydomain.com/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    Download error on https://pypi.mydomain.com/pbr/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    Couldn't find index page for 'pbr' (maybe misspelled?)
    Download error on https://pypi.mydomain.com/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    No local packages or working download links found for pbr>=0.11.0
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-Lsc4UJ/MyLib/setup.py", line 5, in <module>
        pbr=True
      File "/usr/local/pyenv/versions/2.7.13/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/setuptools/dist.py", line 315, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/pkg_resources/__init__.py", line 850, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1122, in best_match
        return self.obtain(req, installer)
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1134, in obtain
        return installer(requirement)
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/local/pyenv/versions/2.7.13/envs/myapp/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('pbr>=0.11.0')

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Lsc4UJ/MyLib/
  1. 有什么方法可以强制 dependency_links 不使用 ~/.pydistutils.cfg 吗?

如果 1 的答案是否定的,那么如何为我的 pypi 服务器忽略 SSL?

尝试了下面给出的解决方案。

# /usr/local/pyenv/versions/myapp/bin/python get-pip.py
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-18.0

/usr/local/pyenv/versions/myapp/bin/pip install -i https://pypi.mydomain.com --trusted-host pypi.mydomain.com -r /opt/school/apps/myapp/requirements.txt
Looking in indexes: https://pypi.mydomain.com
Collecting MyLib==1.2.3 (from -r /opt/school/apps/myapp/requirements.txt (line 1))
  Downloading https://pypi.mydomain.com/packages/MyLib-1.2.3.tar.gz (221kB)
    100% |████████████████████████████████| 225kB 21.2MB/s
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.mydomain.com/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    Download error on https://pypi.mydomain.com/pbr/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    Couldn't find index page for 'pbr' (maybe misspelled?)
    Download error on https://pypi.mydomain.com/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) -- Some packages may not be found!
    No local packages or working download links found for pbr>=0.11.0
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-JD4AuE/MyLib/setup.py", line 5, in <module>
        pbr=True
      File "/usr/local/pyenv/versions/2.7.13/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/setuptools/dist.py", line 315, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/pkg_resources/__init__.py", line 850, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1122, in best_match
        return self.obtain(req, installer)
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1134, in obtain
        return installer(requirement)
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/local/pyenv/versions/cvcollect/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('pbr>=0.11.0')

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-JD4AuE/MyLib/

最佳答案

问题,提到here是,

setuptools is trying to talk to PyPI, not pip, and that 3.6.0 on macOS does not have access to a CA Bundle by default and setuptools doesn't bundle one like pip does. You'll need to install something like certifi or raise an issue with setuptools.

你可以强制安装新版本的pip,

curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
sudo python get-pip.py

您也可以尝试安装 certifi如上期所述,

pip install certifi

Certifi is a carefully curated collection of Root Certificates for validating the trustworthiness of SSL certificates while verifying the identity of TLS hosts. It has been extracted from the Requests project.

可以使用 --trusted-host 禁用 TLS,但它危险并且根本不推荐。

pip install --trusted-host pypi.python.org pip --upgrade

关于python - 忽略 ssl 证书以便于安装 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52488937/

相关文章:

python - 简单合并文件的最快方法是什么?拆分数组的最快方法是什么?

Python Pandas-查找超过阈值的值的第一个实例

jQuery ajax 和 SSL?

Python venv pip 总是过时的

python - 如何安装 Pylint,克服错误

python - pyAV 的 pip 安装失败,退出状态为 1181

python - 每天重新采样到每月一次,并在 pandas 中偏移 'month-end minus t days'

WCF BasicHttpBinding + 用户名密码验证器+x.509

.htaccess - ssl 重定向不工作

python - 如何阻止python在特定虚拟环境中安装模块并全局安装它们?