python - pip 安装 ssh-import-id 时没有名为 'requests' 的模块

标签 python heroku pip

我正在使用 Heroku 作为开发服务器。当我尝试将我的 Django 应用程序推送到 Heroku 时,它首先尝试从 requirements.txt 文件安装我的包。

requests==2.18.3
ssh-import-id==5.5

问题是我的一个包与其他包有依赖关系。在上面的包中,ssh-import-id 需要已经安装了 requests 包。因此,当我推送应用程序时,pip 无法安装并停止部署。

Collecting requests==2.18.3 (from -r re.txt (line 1))
Using cached https://files.pythonhosted.org/packages/ba/92/c35ed010e8f96781f08dfa6d9a6a19445a175a9304aceedece77cd48b68f/requests-2.18.3-py2.py3-none-any.whl
Collecting ssh-import-id==5.5 (from -r re.txt (line 2))
Using cached https://files.pythonhosted.org/packages/66/cc/0a8662a2d2a781db546944f3820b9a3a1a664a47c000577b7fb4db2dfbf8/ssh-import-id-5.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-install-go0a5mxf/ssh-import-id/setup.py", line 20, in <module>
    from ssh_import_id import __version__
  File "/tmp/pip-install-go0a5mxf/ssh-import-id/ssh_import_id/__init__.py", line 25, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-go0a5mxf/ssh-import-id/

我需要使用 pip 一次尝试安装所有列出的包。因为默认情况下 Heroku 运行,pip install -r requirements.txt

最佳答案

is a bug .

库的 setup.py 导入库以获取包含在 setup() 函数调用中的版本...

import os
from setuptools import setup
from ssh_import_id import __version__

... 并且库尝试导入环境中尚不存在的请求。这是 ssh_import_id.__init__.py:

import argparse
import json
import logging
import os
import platform
import requests  # <=== here
import stat
import subprocess
import sys
import tempfile

已添加修复程序,解决需要导入包以获取版本的问题...

import os
from setuptools import setup
import sys


def read_version():
    # shove 'version' into the path so we can import it without going through
    # ssh_import_id which has deps that wont be available at setup.py time.
    # specifically, from 'ssh_import_id import version'
    # will fail due to requests not available.
    verdir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "ssh_import_id"))
    sys.path.insert(0, verdir)
    import version
    return version.VERSION

...但是当前的 pypi 版本 5.6 中没有修复。

您可以通过将 requirements.txt 更改为类似以下内容来从源代码而不是 pypi 安装最新的 master 分支:

-e git+https://git.launchpad.net/ssh-import-id#egg=master

关于python - pip 安装 ssh-import-id 时没有名为 'requests' 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55352889/

相关文章:

python - 如何填充和访问 Django ArrayField?

python - 如何在 Linux 上的 python 中使用以 . 开头的文件/目录?

python - 如何在 python 中获取负数的二进制表示

ruby - 在 gem 中打包预编译的二进制文件

python-3.x - 有没有办法为Windows安装cython-bbox?

python - 使用 pip、easy_install、manual 安装 PyObjc 时遇到问题

python - Jython 图像处理

javascript - Typeahead.js 无法在服务器上运行

java - Heroku Play框架2 sbt依赖项缓存

python - 为什么使用 pip 而不是 easy_install?