【问题标题】:No module named 'requests' when pip installing ssh-import-idpip 安装 ssh-import-id 时没有名为“请求”的模块
【发布时间】:2019-03-26 08:40:07
【问题描述】:

我使用 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

【问题讨论】:

  • 这可能是一个错误。请报告。同时您可以尝试从需求文件中删除请求吗?
  • 这是一个已经在跟踪问题的错误:bugs.launchpad.net/ssh-import-id/+bug/1696021。他们在那里提到了一个修复,但我认为这是在 5.5 之后添加的。
  • 这个问题似乎只影响旧版本的 Python。您应该将 runtime.txt 设置为 python-3.7.2。
  • @SuperShoot 将包从 5.5 更新到最新版本也不起作用。同样的问题
  • 它有完全相同的回溯吗?例如。包括:File "/tmp/pip-install-go0a5mxf/ssh-import-id/setup.py", line 20, in &lt;module&gt; from ssh_import_id import __version__

标签: python heroku pip


【解决方案1】:

这个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 安装最新的主分支:

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

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 2022-07-30
    • 2019-11-07
    • 2015-10-24
    • 2016-10-26
    • 2022-06-27
    • 2017-04-10
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多