无法从 Amazon EC2 中的私有 pypi 服务器获取包
Unable to fetch packages from private pypi server in Amazon EC2
出于几个原因,我们决定在 Amazon S3 上托管所有私有和 public Python 依赖项(及其依赖项)。我们打算 download/install 仅从 S3 而不是其他地方的包。
我按照 (我写了答案)中提到的步骤在 S3 上设置了 pypi 服务器。
要将 public 包上传到 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
)能够安装它们自己和它们的依赖项(numpy
在 pandas
的情况下)没有任何问题。
问题出在非 whl 包上,例如 statsmodels-0.6.1.tar.gz
。 pip
用于安装 statsmodels
,安装依赖项,statsmodels
使用 easy_install
.
pip arg --index-url
未被 easy_install
使用,它会从 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(本地和 EC2 运行 Ubuntu)但在 EC2 运行 Amazon Linux 上失败.下面是我使用 pip 的 --log <file>
参数保存的日志。为了简洁起见,我删除了时间戳。
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
(亚马逊 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"
显然,EC2 运行 Amazon Linux 使用的是 setuptools
的旧版本。
我升级到最新版本并且安装顺利。
出于几个原因,我们决定在 Amazon S3 上托管所有私有和 public Python 依赖项(及其依赖项)。我们打算 download/install 仅从 S3 而不是其他地方的包。
我按照 (我写了答案)中提到的步骤在 S3 上设置了 pypi 服务器。
要将 public 包上传到 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
)能够安装它们自己和它们的依赖项(numpy
在 pandas
的情况下)没有任何问题。
问题出在非 whl 包上,例如 statsmodels-0.6.1.tar.gz
。 pip
用于安装 statsmodels
,安装依赖项,statsmodels
使用 easy_install
.
pip arg --index-url
未被 easy_install
使用,它会从 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(本地和 EC2 运行 Ubuntu)但在 EC2 运行 Amazon Linux 上失败.下面是我使用 pip 的 --log <file>
参数保存的日志。为了简洁起见,我删除了时间戳。
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
(亚马逊 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"
显然,EC2 运行 Amazon Linux 使用的是 setuptools
的旧版本。
我升级到最新版本并且安装顺利。