【问题标题】:Pushing Django app to heroku throws error "ImportError: No module named djangocms_history"将 Django 应用程序推送到 heroku 会引发错误“ImportError: No module named djangocms_history”
【发布时间】:2019-08-25 10:02:32
【问题描述】:

我有一个 Django 项目,我正在尝试将其推送到 heroku。我的 requirements.txt 文件是

Django==1.11.18
django-cms==3.5.3
django-sekizai==0.10.0
django-treebeard==4.3
djangocms-admin-style==1.2.9

当我尝试部署到 heroku 时,出现以下错误:

remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 22, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
remote:            app_config = AppConfig.create(entry)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
remote:            module = import_module(entry)
remote:          File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
remote:            __import__(name)
remote:        ImportError: No module named djangocms_history
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 udsa-content-repository.
remote: 
To https://git.heroku.com/udsa-content-repository.git
 ! [remote rejected] fixing-heroku-build -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/udsa-content-repository.git'

在我激活virtualenv 之前尝试在本地运行命令时,我遇到了同样的错误ImportError: No module named djangocms_history,所以我不知道这是否与它有关。有谁知道如何解决这个问题?

【问题讨论】:

    标签: python django python-2.7 heroku virtualenv


    【解决方案1】:

    您的requirements.txt 文件似乎丢失了:

    djangocms-history==1.0.0
    

    【讨论】:

    • 但是当我所做的只是根据我的 requirements.txt 文件进行 pip 安装时,项目在本地运行得很好,为什么会在 heroku 而不是我的本地导致错误?
    • 您的环境必须已经安装了djangocms-history。请与pip freeze 联系。 Heroku 创建了一个新的干净环境,因此您也需要这样做才能在本地进行更好的测试。
    • 啊,是的,当我做 pip freeze 时,有很多丢失的包。谢谢
    • 其中一些可能是您在 requirements.txt 中拥有的软件包的依赖项。 pipdeptree 或类似的可能会有所帮助。还可以考虑使用Pipenv,它可以帮助您保持清洁的环境。
    【解决方案2】:
    • 运行pip install djangocms-history
    • djangocms_history 添加到您的INSTALLED_APPS
    • 运行python manage.py migrate djangocms_history

    【讨论】:

      【解决方案3】:

      你有一个ImportError

      ImportError for python2.

      转到您的代码,在整个代码库中搜索djangocms_history

      然后pip install djangocms_history,重启你的wsgi,试试看。

      或者注释掉它,以及任何使用它的东西。然后再次尝试运行。

      根据它是什么,您可能还必须进行迁移并且也迁移。

      【讨论】:

        猜你喜欢
        • 2017-09-11
        • 2013-04-07
        • 1970-01-01
        • 1970-01-01
        • 2017-03-16
        • 2011-02-03
        • 1970-01-01
        • 2015-04-30
        • 1970-01-01
        相关资源
        最近更新 更多