ImportError: No module named crispy-forms

Question:

I’m working on some django apps, pretty noob still. Would like to use crispy-forms, but eclipse and django doesnt recognize it.

Trying to runserver or shell:

$ python manage.py runserver

this happens:

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

This is the forms.py I recently added to the site-folder alongside views.py, and it complains about unresolved import of 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'
                )
            )
        )

This is my part of my 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'

I’m running virtualenv, my venv-dir looks like this:

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

I accidentally managed to type in:
pip install python
today, and it seems it did. Could that have any impact on it? I mean, isnt it virtualenv’s task to make sure there is no software-conflicts?

Anyway, I cant get any Django-work going now until i figure this out, any help out there?

Update 1
changes:

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

update 2: Installing a new django-project, new virtualenv, all new.. SAME THING HAPPENS

(abc)nr1@kali:~/workspace/websites/abc$ pip install django-crispy-forms
Collecting django-crispy-forms
Using cached django-crispy-forms-1.4.0.tar.gz
Installing collected packages: django-crispy-forms
Running setup.py install for django-crispy-forms
Successfully installed 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

I now try to install crispy_forms to a completely project, looking in my virtualenv, I see its there:

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

So, its clear. Django doesn’t even recognize that its installed it. How can that be?? virtualenv says its there, but django cant see it??? wtx…

Asked By: beowwwulf

||

Answers:

You have to make sure that you install crispy-forms into the virtualenv.

  1. Activate VirtualEnv (where env is the directory/name of your virtual environment):
source env/bin/activate
  1. Install crispy-forms
pip install django-crispy-forms
Answered By: kristian

As per the documentation : http://django-crispy-forms.readthedocs.org/en/latest/install.html#installing-django-crispy-forms, you have to add ‘crispy_forms’ not ‘crispy-forms’ to your Installed Apps list.

Answered By: Abhishek Agarwala

Ok, so I found by chance(almost) another post, this one: Getting stuck at Django error: No module named registration

and thought it might have something to do with pythonpath.

so then I tried easy_install, like suggested:

 $ 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

Now it works!
I still think there might be something missing with the pythonpath, because I keep getting this in eclipse:

SignUpView Found at: __module_not_in_the_pythonpath__

, and I would like someone to clarify it, so feel free to contribute here…

but django and crispy_forms now works together. YippikayeyMF!!

Answered By: beowwwulf

I use PyCharm for my Django projects. I get exactly the same error as you but in PyCharm until I change the Python interpreter used by PyCharm for the project. I have to, for each project, select the Python interpreter that resides in the relevant virtalenv folder to get the IDE (PyCharm) to recognize the installed modules. I suspect that the Pythonpath lurks somewhere in the background…

Doesn’t Eclipse allow you to select the interpreter to use for a project? That’s where I’d start looking.

Good luck!

Answered By: David Kaplan

I came across the same problem and figured out an alternate way around.

  1. Exit Virtualenv.
  2. Do a fresh pip install of crispy form at the root directory.
  3. Go back to Virtualenv and make migrations followed by migrate.

I think the django installation needs that all third party app be installed inside and as well outside the virtual env.
I would really appreciate if someone could help me with inside details behind the reason.

Answered By: Chiradip

All the above answers are missing one thing. Please cross check the location of your ‘External Libraries’ on the drive first before you do any of the above advises.
Reason:
– You be using an IDE that points to a different python directory, that is for guys who have install python more than once.

  • don’t think your ‘virtualenv’ is pointing to the right directory were your ‘External Libraries’ are stored. So if you go ahead and install in a wrong directory then such error will ok
Answered By: Johnny Camby

I solved this problem right now, I realized that the crispy-form installed version was the python 2.7 version, but I’m using Django-1.10 with Python 3.5, and I think this is your problem too.

Try: pip3 install --user django-crispy-forms

Answered By: Toguko

Your django project is looking for crispy forms module.There is a possibility that it was not installed earlier possibly due to different versions.

If you are using a virtual environment i recommend that after activating your virtual environment you need to install django -crispy-forms.

To install it use command:
pip install django-crispy-forms

Answered By: Dhruv Sawarkar

I was using crispy-forms instead of crispy_forms in settings.py

Following is the overview of things to be done to get crispy forms working:

pip install django-crispy-forms

in settings.py installed apps add crispy_forms
In settings.py add CRISPY_TEMPLATE_PACK = 'bootstrap4'

Answered By: Aseem

change crispy-forms to crispy_forms in the installed apps of settings.py

Answered By: Ahmad Waqar

After activating your virtual environment, assuming you are using python version 3, try:

python3 -m pip install django-crispy-forms
Answered By: motash

I had this same error and all I had to do was runserver using
python3 manage.py runserver. I’m not sure how it works but I think some modules need you to explicitly call python3 and not just the alias.

Answered By: virgoaugustine

I just solved this problem, couldn’t find the solution anywhere though.
This error shows if you haven’t configured the crispy-forms correctly, and do check the version you are using.
Another one that worked for me- I configured everything perfect, But didn’t noticed some minor issues with the project and the app I configured.
Go through the whole process again and everything will be good to go.

Answered By: Agnishwar

For me , I just had to update the python version and it solved the problem. I was using python 3.9 , but then I uninstalled it and installed python 3.10 and also installed the latest version of django after uninstalling the previous version.

Note : don’t forget to change your environment variables after making the changes!

Answered By: Aditi

After pip installed the crispy-forms library, added crispy_forms in the installed_apps. The issue for me was at the forms.py, my VScode editor does not recognized the crispy_forms.helper. Solution – I just close my Editor and then open again and now its recognized.

Answered By: elekson

This helped me. Try to use pipenv as a development environment.

  1. Install pipenv via pip

    pip3 install --user pipenv

  2. Install packages you need

    pipenv install django-crispy-forms

  3. Run pipenv shell

    pipenv shell

  4. Run your server

    pipenv run python3 manage.py runserver

Answered By: Narek