【问题标题】:Heroku: ModuleNotFoundError :No module named 'requests'Heroku:ModuleNotFoundError:没有名为“请求”的模块
【发布时间】:2019-08-11 20:27:29
【问题描述】:

我正在尝试将 Django 程序部署到 Heroku。该应用程序在我使用 Anaconda 和 Python 3.5 的本地计算机上成功运行。我无法将其推送到 Heroku。根据命令

>git push heroku master

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote:  !     Python has released a security update! Please consider upgrading to python-3.6.8
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.6.2
remote: -----> Installing pip
remote: -----> Installing dependencies with Pipenv 2018.5.18…
remote:        Installing dependencies from Pipfile.lock (958efe)…
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 15, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
remote:            app_config = AppConfig.create(entry)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
remote:            module = import_module(entry)
remote:          File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 978, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 961, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
remote:        ModuleNotFoundError: No module named 'requests'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to [redacted].

我不确定为什么我无法在 Heroku 中将 requests 模块安装为 pip。它在我的requirements.txt 文件中:

Django==2.1.7
dj-database-url==0.5.0
dj-static==0.0.6
gunicorn==19.9.0
Unipath==1.1
python-decouple==3.1
Pillow==3.3.0
Markdown==3.0.1
bleach==3.1.0
psycopg2==2.7.7
whitenoise==4.1.2
requests==2.21.0
requests-oauthlib==1.0.0

【问题讨论】:

    标签: python django heroku importerror


    【解决方案1】:

    您的 Heroku 构建的输出显示,除了您的 requirements.txt 之外,您还有一个 PipfilePipfile.lock

    您需要在使用 pip(使用 requirements.txt)或 Pipenv(使用 PipfilePipfile.lock)之间进行选择。如果所有三个文件都存在,Heroku 将使用 Pipenv 安装,忽略您的 requirements.txt 文件。

    要么

    • 将您的需求移至您的 Pipfile 并在本地运行 Pipenv 以安装它们并更新您的 Pipfile.lock、删除您的 requirements.txt、提交并推送(以使用 Pipenv),或者
    • 删除PipfilePipfile.lock,在本地使用pip(或pip-tools 或类似名称),提交并推送(以使用pip)。

    【讨论】:

    • 谢谢,如何删除pipenv? Pipfile 和 Pipfile.lock 似乎不是我目录中的文件。
    • 您本地没有这些文件?你100%确定吗?您在本地使用哪些工具进行虚拟环境和依赖管理?
    • @emericaism,你还有这个问题吗?你搞定了吗?
    • @Chris 嘿,克里斯,我也有类似的问题,你介意看看我的问题吗? stackoverflow.com/questions/57336072/…
    猜你喜欢
    • 1970-01-01
    • 2015-12-23
    • 2017-12-08
    • 2013-06-22
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多