ImportError:没有名为crispy-forms的模块

beo*_*ulf 10 python django django-crispy-forms

我正在研究一些django应用程序,还有漂亮的菜鸟.想使用香脆的形式,但是eclipse和django并不认识它.

尝试运行server或shell:

$ python manage.py runserver
Run Code Online (Sandbox Code Playgroud)

有时候是这样的:

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
Run Code Online (Sandbox Code Playgroud)

这是我最近在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'
                )
            )
        )
Run Code Online (Sandbox Code Playgroud)

这是我的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'
Run Code Online (Sandbox Code Playgroud)

我正在运行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
Run Code Online (Sandbox Code Playgroud)

我不小心设法输入:今天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
Run Code Online (Sandbox Code Playgroud)

更新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
Run Code Online (Sandbox Code Playgroud)

我现在尝试将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
Run Code Online (Sandbox Code Playgroud)

所以,它清楚.Django甚至不承认它安装了它.怎么可能??virtualenv说它在那里,但django不能看到它?WTX ...

小智 12

我现在解决了这个问题,我意识到安装的脆形式版本是python 2.7版本,但我使用的是Django-1.10和python 3.5,我认为这也是你的问题.

尝试: pip3 install --user django-crispy-forms


kri*_*ian 8

您必须确保将crispy-forms安装到virtualenv中.

  1. 激活VirtualEnv(其中env是虚拟环境的目录/名称):

    source env/bin/activate

  2. 安装香脆形式

    pip安装django-crispy-forms


小智 6

根据文档:http : //django-crispy-forms.readthedocs.org/en/latest/install.html#installing-django-crispy-forms,您必须在您的计算机上添加“ crispy_forms”而不是“ crispy-forms”已安装的应用程序列表。


Ase*_*eem 6

我在 settings.py 中使用crispy-forms而不是crispy_forms

以下是使脆皮表格工作所需要做的事情的概述:

pip install django-crispy-forms
Run Code Online (Sandbox Code Playgroud)

在 settings.py 安装的应用程序中添加crispy_forms 在 settings.py 添加CRISPY_TEMPLATE_PACK = 'bootstrap4'


beo*_*ulf 2

好的,所以我偶然(几乎)发现了另一篇文章,这个:Getting 卡在 Django 错误:没有名为注册的模块

并认为这可能与 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
Run Code Online (Sandbox Code Playgroud)

现在可以了!我仍然认为 pythonpath 可能缺少一些东西,因为我一直在 eclipse 中得到这个:

SignUpView Found at: __module_not_in_the_pythonpath__
Run Code Online (Sandbox Code Playgroud)

,我希望有人能澄清这一点,所以请随意在这里做出贡献......

但 django 和 Crispy_forms 现在可以一起工作。伊皮卡伊MF!!