2


我可以导入crispy_forms,但是当我运行python3 manage.py runserver
它时说没有名为crispy_forms的模块,我不知道为什么会这样,因为当我运行时pip3 list,我可以看到django-crispy-forms。
所以我附上了我的解释器设置,真的需要你的帮助
解释器设置图像

和终端中的错误消息

 >>> python3 manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/eunwoo/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/Users/eunwoo/anaconda3/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
    raise _exception[1]
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/eunwoo/anaconda3/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/Users/eunwoo/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crispy_forms'

4

4 回答 4

0

我有同样的错误。正如@erdin-eray所说,我必须加上"crispy_forms"双引号,然后尝试重新导入. 这为我解决了。pip install django-crispy-forms

原来我第一次做的时候pip install ...我不在我的(env)虚拟环境中!

点冻结> 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-11-20T01:50:25.490 回答
0

如果您正在使用 pipenv 并为您的项目创建虚拟环境,您可能需要在虚拟环境的 shell 中。尝试使用

python3 -m pipenv shell

启动虚拟环境的外壳。您可以使用以下命令检查以确保已安装 django-crispy-forms

pip list

命令。如果您在此列表中看到安装了所需版本的 django-crispy-forms,请尝试使用您最初使用的相同命令再次运行服务器:

python3 manage.py runserver
于 2021-12-27T18:06:21.530 回答
-1

pip install django-crispy-forms 不适用于此错误。您需要使用 python 命令而不是 python3 来运行服务器。

于 2021-07-15T16:50:39.753 回答
-1
pip install django-crispy-forms
于 2020-06-21T16:36:23.590 回答