返回

python-django crispy forms ModuleNotFoundError,但可以在控制台中导入

发布时间:2022-04-19 16:45:10 341
# node.js

我已经试着让酥脆的表单工作了3个小时,现在它快把我逼疯了,请帮帮我!(或者建议另一种/更好的方式在django中设计表单?!)

我在已安装的应用程序中添加了crispy_表单,如下所示:

INSTALLED_APPS = [
   ...
   'crispy_forms',
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

我在windows 10上,使用pycharm pro和venv。对于我安装的所有其他设备,解释器都可以正常工作。在终点站我可以跑步python然后import crispy_forms没有错误,但如果我尝试进行迁移或运行服务器,pycharm会抛出ModuleNotFoundError。

我尝试切换“将内容和源根添加到系统路径”;但老实说,我真的不明白,不管怎样,这都没有帮助。

谢谢

终端输出:

PS E:\Dev\Spotify\spo_djangos> pip show django-crispy-forms
Name: django-crispy-forms
Version: 1.14.0
Summary: Best way to have Django DRY forms
Home-page: https://github.com/django-crispy-forms/django-crispy-forms
Author: Miguel Araujo
Author-email: miguel.araujo.perez@gmail.com
License: MIT
Location: c:\users\ryzen\appdata\local\programs\python\python310\lib\site-packages

PS E:\Dev\Spotify\spo_djangos> python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import crispy_forms
>>>

python回溯:

E:\Dev\Spotify\spo_djangos\.venv\python.exe E:/Dev/Spotify/spo_djangos/manage.py runserver 8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\site-packages\django\apps\config.py", line 224, in create
    import_module(entry)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crispy_forms'

使现代化

我在安装crispy form后出现了错误

并得到了foplowing错误:

Error: Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.1\plugins\python\helpers\packaging_tool.py", line 73, in run_pip
    runpy.run_module(module_name, run_name='__main__', alter_sys=True)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\__main__.py", line 29, in 
    from pip._internal.cli.main import main as _main
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\main.py", line 9, in 
    from pip._internal.cli.autocompletion import autocomplete
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in 
    from pip._internal.cli.main_parser import create_main_parser
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in 
    from pip._internal.cli import cmdoptions
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 23, in 
    from pip._internal.cli.parser import ConfigOptionParser
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\parser.py", line 12, in 
    from pip._internal.configuration import Configuration, ConfigurationError
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\configuration.py", line 20, in 
    from pip._internal.exceptions import (
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\exceptions.py", line 7, in 
    from pip._vendor.pkg_resources import Distribution
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 80, in 
    from pip._vendor import platformdirs
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 31, in 
    PlatformDirs = _set_platform_dir_class()  #: Currently active platform
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 27, in _set_platform_dir_class
    result: Type[PlatformDirsABC] = getattr(importlib.import_module(module), name)
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_vendor\platformdirs\windows.py", line 1, in 
    import ctypes
  File "E:\Dev\Spotify\spo_djangos\.venv\lib\ctypes\__init__.py", line 8, in 
    from _ctypes import Union, Structure, Array
ImportError: DLL load failed while importing _ctypes: The specified module could not be found.

pycharm错误详细信息显示要运行E:\Dev\Spotify\spo_djangos2\venv\Scripts\activate.bat PS E:\Dev\Spotify\spo_djangos> pip install django-crispy-forms在最后一刻,我做到了。没有错误,但仍然得到modulenotfound错误

PS E:\Dev\Spotify\spo_djangos> E:\Dev\Spotify\spo_djangos2\venv\Scripts\activate.bat
PS E:\Dev\Spotify\spo_djangos> pip install django-crispy-forms
Collecting django-crispy-forms
  Using cached django_crispy_forms-1.14.0-py3-none-any.whl (133 kB)
Installing collected packages: django-crispy-forms
Successfully installed django-crispy-forms-1.14.0
PS E:\Dev\Spotify\spo_djangos> pip show django-crispy-forms
Name: django-crispy-forms
Version: 1.14.0
Summary: Best way to have Django DRY forms
Home-page: https://github.com/django-crispy-forms/django-crispy-forms
Author: Miguel Araujo
Author-email: miguel.araujo.perez@gmail.com
License: MIT
Location: c:\users\ryzen\appdata\local\programs\python\python310\lib\site-packages
Requires:
Required-by:
PS E:\Dev\Spotify\spo_djangos> 

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(2)
按点赞数排序
用户头像