本地pypi包依赖python pypi server

Posted

技术标签:

【中文标题】本地pypi包依赖python pypi server【英文标题】:local pypi package depends on python pypi server 【发布时间】:2018-07-04 00:26:17 【问题描述】:

我创建了本地 pypi 服务器http://localhost:8080/simple。我上传了我的项目需要的包flask-mongoengine,但是当tox 尝试为pip install 执行nose 的包依赖项时,它尝试从pypi.python.org 下载

Collecting flask-mongoengine==0.9.2 (from -r requirements.txt (line 14))
  Downloading https://localhost:8080/packages/flask-mongoengine-0.9.2.tar.gz (112kB)
    100% |████████████████████████████████| 112kB 26.8MB/s
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.python.org/simple/nose/: [Errno 101] Network is unreachable -- Some packages may not be found!
    Couldn't find index page for 'nose' (maybe misspelled?)
    Download error on https://pypi.python.org/simple/: [Errno 101] Network is unreachable -- Some packages may not be found!
    No local packages or working download links found for nose
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-n57wg0y0/flask-mongoengine/setup.py", line 74, in <module>
        'Topic :: Software Development :: Libraries :: Python Modules'
      File "/var/lib/jenkins/.pyenv/versions/3.5.2/lib/python3.5/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/setuptools/dist.py", line 315, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
        replace_conflicting=True,
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 850, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1122, in best_match
        return self.obtain(req, installer)
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1134, in obtain
        return installer(requirement)
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
        return cmd.easy_install(req)
      File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/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('nose')

我的pypi 服务器有nose 包,但不知怎么的,它没有重定向到那个。

尝试了第一个答案,它给出了错误

Traceback (most recent call last):
  File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/pip/req/req_install.py", line 82, in __init__
    req = Requirement(req)
  File "/var/lib/jenkins/workspace/myproject/.tox/py35/lib/python3.5/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'[global]'"

ERROR: InvocationError: '/var/lib/jenkins/workspace/myproject/.tox/py35/bin/pip install -i http://localhost:8080 --trusted-host localhost:8080 -r requirements.txt'

【问题讨论】:

【参考方案1】:

指定默认指向本地主机?在$HOME/.pypirc

[distutils]
index-servers =
    localpypi

[localpypi]
repository: http://localhost:8080/simple
username:<your_localpypi_username>
password:<your_localpypi_passwd>

requirements.txt 稍远一点,这样的东西可能会代替.pypirc,或者可能需要它来补充:

# requirements.txt
--index-url http://localhost:8080/simple
--trusted-host localhost:8080
flask-mongoengine

对于$HOME/.config/pip/pip.conf

[global]
timeout = 1
index-url = http://localhost:8080/simple
trusted-host = localhost:8080

是的,这也可能:

https://pypi.python.org/pypi/pypiserver#uploading-packages-remotely

也许:

python setup.py dist upload -r http://localhost:8080/simple

如果 pypi 需要任何依赖项,那么:

PyPI local cache for Jenkins/local builds how to create local own pypi repository index without mirror?

我对所有可以设置 --index-url--extra-index-url 的地方感到困惑,但我的想法是为 pypi 和 pip 设置 index-url?

【讨论】:

仍然是同样的错误,我认为,distutils 将被使用,当您尝试执行 dist upload 时。 谢谢@jmunsch,但我不想上传。我想下载包。对于dist upload,它可以工作,但flask-mongoengine 不是我的包,我的项目依赖于它。 @Nilesh 所以也许--extra-index-url 认为它是一个完全本地的 pypi 服务器? @Nilesh 更新,所以想了一下,也许试试[global] pip.conf 的东西,我忘了 requirements.txt 和 pip.conf 使用不同的格式。希望对您有所帮助。

以上是关于本地pypi包依赖python pypi server的主要内容,如果未能解决你的问题,请参考以下文章

通过 pip (PyPI) 安装 Python 实时依赖项 [重复]

Python 第三方包上传至 PyPI 服务器

pip 无法从本地 pypi (jfrog artifactory) 找到包

发布本地的python程序到pypi服务器

Python 进阶 — 创建本地 PyPI 仓库

防止私有和基于 pypi 的 Python 包之间的命名空间冲突