我正在开发一些django应用程序,还有漂亮的noob。想使用香脆的形式,但是eclipse和django不会识别它。
尝试运行server或shell:
$ python manage.py runserver
这种情况发生了:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named crispy-forms
这是我最近在views.py旁边添加到site-folder的forms.py,它抱怨未解决的crispy_forms导入......:
from django.contrib.auth.forms import UserCreationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, ButtonHolder, Submit
from wx.lib.pubsub.core import kwargs
class RegistrationForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
'username',
'password1',
'password2',
ButtonHolder(
Submit('register',
'Register',
css_class='btn-prima'
)
)
)
这是我的settings.py:
的一部分 INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'crispy-forms',
)
...
CRISPY_TEMPLATE_PACK = 'bootstrap'
我正在运行virtualenv,我的venv-dir看起来像这样:
venv/bin$ ls -la
total 2916
drwxr-xr-x 3 nr1 nr1 4096 Feb 17 11:24 .
drwxr-xr-x 6 nr1 nr1 4096 Feb 16 19:38 ..
-rw-r--r-- 1 nr1 nr1 2220 Feb 16 19:35 activate
-rw-r--r-- 1 nr1 nr1 1276 Feb 16 19:35 activate.csh
-rw-r--r-- 1 nr1 nr1 2489 Feb 16 19:35 activate.fish
-rw-r--r-- 1 nr1 nr1 1137 Feb 16 19:35 activate_this.py
-rwxr-xr-x 1 nr1 nr1 300 Feb 16 19:44 django-admin
-rwxr-xr-x 1 nr1 nr1 159 Feb 16 19:44 django-admin.py
-rw-r--r-- 1 nr1 nr1 304 Feb 16 19:44 django-admin.pyc
-rwxr-xr-x 1 nr1 nr1 267 Feb 17 11:24 easy_install
-rwxr-xr-x 1 nr1 nr1 267 Feb 17 11:24 easy_install-2.7
drwxr-xr-x 7 nr1 nr1 4096 Feb 16 19:47 .git
-rwxr-xr-x 1 nr1 nr1 2364 Feb 17 00:13 pilconvert.py
-rwxr-xr-x 1 nr1 nr1 15631 Feb 17 00:13 pildriver.py
-rwxr-xr-x 1 nr1 nr1 2609 Feb 17 00:13 pilfile.py
-rwxr-xr-x 1 nr1 nr1 1055 Feb 17 00:13 pilfont.py
-rwxr-xr-x 1 nr1 nr1 2410 Feb 17 00:13 pilprint.py
-rwxr-xr-x 1 nr1 nr1 239 Feb 17 11:24 pip
-rwxr-xr-x 1 nr1 nr1 239 Feb 17 11:24 pip2
-rwxr-xr-x 1 nr1 nr1 239 Feb 17 11:24 pip2.7
-rwxr-xr-x 1 nr1 nr1 2884984 Feb 17 11:24 python
lrwxrwxrwx 1 nr1 nr1 6 Feb 17 11:24 python2 -> python
lrwxrwxrwx 1 nr1 nr1 6 Feb 17 11:24 python2.7 -> python
-rwxr-xr-x 1 nr1 nr1 3886 Feb 17 00:11 sqlformat
我无意中输入了: pip install python 今天,它似乎确实如此。这会对它产生什么影响吗?我的意思是,这不是virtualenv的任务,以确保没有软件冲突?
无论如何,我现在无法进行任何Django工作,直到我弄清楚,有什么帮助吗?
更新1 变化:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'crispy_forms',
)
$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named crispy_forms
$ cat requirements.txt
Django==1.7.4
django-crispy-forms==1.4.0
django-debug-toolbar==1.2.2
django-extras==0.3
django-grappelli==2.6.3
django-haystack==2.3.1
django-reversion==1.8.5
django-tastypie==0.12.1
easy-thumbnails==2.2
Pillow==2.7.0
python-dateutil==2.4.0
python-mimeparse==0.1.4
requests==2.5.1
six==1.9.0
sqlparse==0.1.14
更新2:安装一个新的django项目,新的virtualenv,全新..同样的事情发生
(abc)nr1 @ kali:〜/ workspace / websites / abc $ pip install django-crispy-forms 收集django-crispy-forms 使用缓存的django-crispy-forms-1.4.0.tar.gz 安装收集的包:django-crispy-forms 运行django-crispy-forms的setup.py安装 已成功安装django-crispy-forms-1.4.0
(abc)nr1@kali:~/workspace/websites/abc$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/nr1/Envs/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/nr1/Envs/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/nr1/Envs/abc/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/nr1/Envs/abc/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/nr1/Envs/abc/local/lib/python2.7/site-packages/django/apps/config.py", line 123, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named crispy_forms
我现在尝试将crispy_forms安装到一个完整的项目中,看看我的virtualenv,我看到它在那里:
nr1@kali:~/Envs/abc/local/lib/python2.7/site-packages$ ls -la
total 56
drwxr-xr-x 12 nr1 nr1 4096 Feb 17 21:50 .
drwxr-xr-x 4 nr1 nr1 4096 Feb 17 20:31 ..
drwxr-xr-x 5 nr1 nr1 4096 Feb 17 21:50 crispy_forms
drwxr-xr-x 17 nr1 nr1 4096 Feb 17 20:40 django
drwxr-xr-x 2 nr1 nr1 4096 Feb 17 20:40 Django-1.7.4.dist-info
drwxr-xr-x 2 nr1 nr1 4096 Feb 17 21:50 django_crispy_forms-1.4.0-py2.7.egg-info
-rw-r--r-- 1 nr1 nr1 126 Feb 17 20:31 easy_install.py
-rw-r--r-- 1 nr1 nr1 315 Feb 17 20:31 easy_install.pyc
drwxr-xr-x 2 nr1 nr1 4096 Feb 17 20:31 _markerlib
drwxr-xr-x 10 nr1 nr1 4096 Feb 17 20:31 pip
drwxr-xr-x 2 nr1 nr1 4096 Feb 17 20:31 pip-6.0.8.dist-info
drwxr-xr-x 4 nr1 nr1 4096 Feb 17 20:31 pkg_resources
drwxr-xr-x 4 nr1 nr1 4096 Feb 17 20:31 setuptools
drwxr-xr-x 2 nr1 nr1 4096 Feb 17 20:31 setuptools-12.0.5.dist-info
所以,很清楚。 Django甚至不承认它安装了它。怎么可能?? virtualenv说它在那里,但django不能看到它? WTX ...
答案 0 :(得分:10)
我现在解决了这个问题,我意识到安装的脆形式版本是python 2.7版本,但我使用的是Django-1.10和python 3.5,我认为这也是你的问题。
尝试:pip3 install --user django-crispy-forms
答案 1 :(得分:5)
您必须确保将crispy-forms安装到virtualenv中。
激活VirtualEnv(其中env是虚拟环境的目录/名称):
source env / bin / activate
安装crispy-forms
pip install django-crispy-forms
答案 2 :(得分:4)
根据文档:http://django-crispy-forms.readthedocs.org/en/latest/install.html#installing-django-crispy-forms,您必须在已安装的应用列表中添加'crispy_forms'而不是'crispy-forms'。
答案 3 :(得分:3)
我在settings.py中使用的是crispy-forms
而不是crispy_forms
以下是使酥脆的表格正常工作的概述:
pip install django-crispy-forms
在settings.py安装的应用中添加crispy_forms
在settings.py中添加CRISPY_TEMPLATE_PACK = 'bootstrap4'
答案 4 :(得分:2)
好的,所以我偶然发现了另外一篇文章:Getting stuck at Django error: No module named registration
并认为它可能与pythonpath有关。
然后我尝试了easy_install,如建议:
$ easy_install -Z django-crispy-forms
Searching for django-crispy-forms
Best match: django-crispy-forms 1.4.0
Adding django-crispy-forms 1.4.0 to easy-install.pth file
Using /home/nr1/Envs/abc/lib/python2.7/site-packages
Processing dependencies for django-crispy-forms
Finished processing dependencies for django-crispy-forms
现在它有效! 我仍然认为pythonpath可能会遗漏一些东西,因为我一直在eclipse中得到这个:
SignUpView Found at: __module_not_in_the_pythonpath__
,我希望有人澄清一下,所以请随时在这里做出贡献......
但是django和crispy_forms现在一起工作。 YippikayeyMF !!
答案 5 :(得分:1)
我将PyCharm用于我的Django项目。我得到了与你完全相同的错误,但在PyCharm中,直到我更改了PyCharm用于项目的Python解释器。我必须为每个项目选择驻留在相关virtalenv文件夹中的Python解释器,以使IDE(PyCharm)识别已安装的模块。我怀疑Pythonpath潜伏在后台...
Eclipse不允许您选择用于项目的解释器吗?这就是我开始寻找的地方。
祝你好运!答案 6 :(得分:0)
我遇到了同样的问题并想出了另一种方法。
我认为django安装需要将所有第三方应用程序安装在虚拟环境内以及虚拟环境之外。 如果有人能帮助我了解原因背后的细节,我真的很感激。
答案 7 :(得分:0)
以上所有答案都缺少一件事。在进行上述任何建议之前,请先在驱动器上交叉检查“外部库”的位置。 原因: - 您正在使用指向不同python目录的IDE,这适用于已经多次安装python的人。
答案 8 :(得分:0)
您的django项目正在寻找酥脆的表格模块。由于版本不同,它可能没有更早安装。
如果您使用的是虚拟环境,我建议您在激活虚拟环境后需要安装django -crispy-forms。
要安装它,请使用命令: pip安装django-crispy-forms答案 9 :(得分:0)
在已安装的settings.py应用程序中将crispy-forms更改为crispy_forms
答案 10 :(得分:0)
激活虚拟环境后,假设您使用的是 Python 版本 3,请尝试:
python3 -m pip install django-crispy-forms
答案 11 :(得分:-1)
我遇到了同样的错误,我所要做的就是使用 runserver
python3 manage.py runserver
。我不确定它是如何工作的,但我认为有些模块需要您显式调用 python3 而不仅仅是别名。