【问题标题】:ModuleNotFoundError: No module named 'crispy_forms'ModuleNotFoundError:没有名为“crispy_forms”的模块
【发布时间】:2020-12-21 18:11:04
【问题描述】:

django-crispy-forms 存在于 requirements.txt 中(使用 pip freeze > requirements.txt 添加) requirements.txt

asgiref==3.2.10
autopep8==1.5.4
beautifulsoup4==4.9.1
certifi==2020.6.20
chardet==3.0.4
Django==3.1
django-crispy-forms==1.9.2
feedparser==5.2.1
idna==2.10
Pillow==7.2.0
pycodestyle==2.6.0
python-dateutil==2.8.1
pytz==2020.1
requests==2.24.0
six==1.15.0
soupsieve==2.0.1
sqlparse==0.3.1
toml==0.10.1
urllib3==1.25.10

heroku 运行 pip 冻结

appdirs==1.4.4
asgiref==3.2.10
certifi==2020.6.20
distlib==0.3.1
Django==3.1.1
filelock==3.0.12
gunicorn==20.0.4
pipenv==2018.5.18
pytz==2020.1
six==1.15.0
sqlparse==0.3.1
virtualenv==20.0.31
virtualenv-clone==0.5.4
whitenoise==5.2.0

因此,这会导致 heroku 部署时出现应用程序错误,heroku logs --tail 给出了ModuleNotFoundError: No module named 'crispy_forms'

【问题讨论】:

  • 请注意,该错误为您提供了crispy_forms 的值,而不是django-crispy-forms。我敢打赌这就是为什么你有这个错误。如果这不起作用,请发送一些消息
  • 确保您已提交更改并将更改推送到requirements.txt
  • @zot8 有什么办法让它正确吗?
  • @Alasdair 是的,更改已提交并推送。
  • @zot8 你 import crispy_forms

标签: python django heroku deployment


【解决方案1】:

// 请在此处查看我的答案:https://stackoverflow.com/a/64922610/1965726

我有同样的错误。我不得不将"crispy_forms" 放在双引号中,然后尝试使用pip install django-crispy-forms 重新导入。这为我解决了。

原来我第一次执行“pip install”时我不在我的 (env) 虚拟环境中,所以我认为我已经成功安装了它。

pip freeze > requirements.txt:

asgiref==3.3.1
Django==3.1.3
django-crispy-forms==1.10.0
pkg-resources==0.0.0
pytz==2020.4
sqlparse==0.4.1

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 1970-01-01
    • 2019-03-28
    • 2022-01-07
    • 2017-12-14
    • 2020-12-10
    • 2021-09-02
    • 2020-10-10
    相关资源
    最近更新 更多