我一直在尝试让脆的形式工作了3个小时,现在它把我逼疯了,请帮助!(或建议其他/更好的方式来风格形式在django?!)
我已将crispy_forms添加到已安装的应用程序中,作为:
INSTALLED_APPS = [
...
'crispy_forms',
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
我在windows 10上,使用pycharm-pro和venv。解释器对我安装的其他东西都很好。在终端中,我可以运行python
,然后运行import crispy_forms
,没有错误,但如果我试图进行迁移或运行服务器,pycharm会抛出ModuleNotFoundError。
我试着切换“添加内容和源根到系统路径”,但老实说,我真的不明白,在任何情况下,它没有帮助...
谢谢!2!
终端输出:
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 "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crispy_forms'
我的解释器配置:
更新过
安装crispy form后出现错误
得到如下误差:
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 <module>
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 <module>
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 <module>
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 <module>
from pip._internal.cli import cmdoptions
File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 23, in <module>
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 <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\configuration.py", line 20, in <module>
from pip._internal.exceptions import (
File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_internal\exceptions.py", line 7, in <module>
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 <module>
from pip._vendor import platformdirs
File "E:\Dev\Spotify\spo_djangos2\venv\lib\site-packages\pip\_vendor\platformdirs\__init__.py", line 31, in <module>
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 <module>
import ctypes
File "E:\Dev\Spotify\spo_djangos\.venv\lib\ctypes\__init__.py", line 8, in <module>
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
在终端sop我做了。没有错误,但仍然得到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>
1条答案
按热度按时间o0lyfsai1#
windows执行策略是干扰,activate.bat是失败的沉默,所以我认为venv被激活,但我只是在venv目录。
调整了执行策略并安装了清晰的表单。
希望这可以帮助别人的一天!(这里的指示,不要设置他们太自由!!https://learn.microsoft.com/en-gb/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.)