簡體   English   中英

無法從 Amazon EC2 中的私有 pypi 服務器獲取包

[英]Unable to fetch packages from private pypi server in Amazon EC2

出於幾個原因,我們決定在 Amazon S3 上托管我們所有的私有和公共 Python 依賴項(及其依賴項)。 我們打算僅從 S3 下載/安裝軟件包,而不會從其他任何地方下載/安裝軟件包。

我按照https://stackoverflow.com/a/57552988/3007402 (我寫了答案)中提到的步驟在 S3 上設置了 pypi 服務器。

要將公共包上傳到 S3,我會首先使用
pip download numpy==1.14.2
pip download statsmodels==0.6.1

要安裝我會使用的任何軟件包

pip install pandas --index-url=http://<s3_endpoint> --trusted-host=<s3_endpoint> --no-cache-dir

對於下載為.whl文件的軟件包,一切正常。 這樣的包(例如pandas )能夠毫無問題地安裝它們自己和它們的依賴項(在pandas情況下為numpy )。

問題在於非 whl 軟件包,例如statsmodels-0.6.1.tar.gz 雖然pip用於安裝statsmodels ,但要安裝依賴項, statsmodels使用easy_install
easy_install不使用 pip arg --index-url ,它會從 pypi.org 下載依賴項 - numpy

為了解決這個問題(僅從 S3 下載),我提取了statsmodels-0.6.1.tar.gz ,編輯了setup.cfg ,重新打包並上傳到 S3。 下面是setup.cfg的內容:

[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

# lines below are added by me
[easy_install]
index_url = http://<s3_link>
find_links = http://<s3_link>

通過該更改statsmodels從 S3 獲取依賴項numpy並成功安裝它。

出於某種奇怪的原因,這僅適用於 Ubuntu(本地和運行 Ubuntu 的 EC2),但在運行 Amazon Linux 的 EC2 上失敗。 下面是我使用--log <file>參數保存到 pip 的日志。 為簡潔起見,我刪除了時間戳。

Created temporary directory: /tmp/pip-ephem-wheel-cache-7SD5Bu
Created temporary directory: /tmp/pip-req-tracker-du4AEi
Created requirements tracker '/tmp/pip-req-tracker-du4AEi'
Created temporary directory: /tmp/pip-install-G2qw36
Looking in indexes: http://<s3_link>
Collecting statsmodels
  1 location(s) to search for versions of statsmodels:
  * http://<s3_link>/statsmodels/
  Getting page http://<s3_link>/statsmodels/
  Found index url http://<s3_link>
  Analyzing links from page http://<s3_link>/statsmodels/
    Found link http://<s3_link>/statsmodels/statsmodels-0.6.1.tar.gz (from http://<s3_link>/statsmodels/), version: 0.6.1
  Given no hashes to check 1 links for project 'statsmodels': discarding no candidates
  Using version 0.6.1 (newest of versions: 0.6.1)
  Created temporary directory: /tmp/pip-unpack-r8lKU4
  Found index url http://<s3_link>
  Downloading http://<s3_link>/statsmodels/statsmodels-0.6.1.tar.gz (7.1MB)
  Downloading from URL http://<s3_link>/statsmodels/statsmodels-0.6.1.tar.gz (from http://<s3_link>/statsmodels/)
  Added statsmodels from http://<s3_link>/statsmodels/statsmodels-0.6.1.tar.gz to build tracker '/tmp/pip-req-tracker-du4AEi'
    Running setup.py (path:/tmp/pip-install-G2qw36/statsmodels/setup.py) egg_info for package statsmodels
    Running command python setup.py egg_info
    No local packages or download links found for numpy
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-G2qw36/statsmodels/setup.py", line 449, in <module>
        **setuptools_kwargs)
      File "/usr/lib64/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/setuptools/dist.py", line 265, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/setuptools/dist.py", line 311, in fetch_build_eggs
        replace_conflicting=True,
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 797, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1047, in best_match
        return self.obtain(req, installer)
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1059, in obtain
        return installer(requirement)
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/setuptools/dist.py", line 378, in fetch_build_egg
        return cmd.easy_install(req)
      File "/home/ec2-user/tempenv/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 617, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('numpy')

cat /etc/os-release (Amazon Linux 詳細信息):

NAME="Amazon Linux AMI"
VERSION="2017.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2017.03"
PRETTY_NAME="Amazon Linux AMI 2017.03"

顯然,運行 Amazon Linux 的 EC2 使用的是舊版本的setuptools
我升級到最新版本,安裝正常。 😅

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM