I am using Django 1.7.1 and I pip installed django-filters to my virtual env at
/.virtualenvs/auction2/lib/python2.7/site-packages$
It said it was installed successfully.
So I placed django-filters in installed apps like so:
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'crispy_forms', 'django_filters', 'donations', )
I ran
python manage.py runserver
and got this error:Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/Dani/.virtualenvs/auction2/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/Users/Dani/.virtualenvs/auction2/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute django.setup() File "/Users/Dani/.virtualenvs/auction2/lib/python2.7/site-packages/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/Dani/.virtualenvs/auction2/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate app_config = AppConfig.create(entry) File "/Users/Dani/.virtualenvs/auction2/lib/python2.7/site-packages/django/apps/config.py", line 87, in create module = import_module(entry) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) ImportError: No module named django_filters
It said it installed, but why can't it import it? I have another package, crispy-forms, installed and working. I looked at my site packages on the virtual environment and I saw:
crispy_forms django django_braces-1.4.0.dist-info django_crispy_forms-1.4.0-py2.7.egg-info django_filters-0.1.0-py2.7.egg-info easy_install.py easy_install.pyc filters pip
Seeing that it goes in as 'filters' instead of what the documentation says to import it as (django_filters), I thought I'd try changing it to just 'filters' in installed_apps.
I stoped and started the runserver, no problem, so I began building my filter in
filter.py
:import django_filters from donations.models import Donor, Item, Issue class DonorFilter(django_filters.FilterSet): class Meta: model = Donor fields = {'type':['exact'],'donor':['icontains'],} def __init__(self, *args, **kwargs): super(DonorFilter, self).__init__(*args, **kwargs) self.filters['type'].extra.update( {'empty_label': 'All Types'})
I stop and start the runserver, no problem. Then I start adding a view and just the import statement at views.py:
from donations.filters import DonorFilter
gives me the same
ImportError: No module named django_filters.
error.I tried changing the import in my filters.py to filters rather than django_filters and the errors didn't change. I changed everything back to django_filters (in installed_apps and my filters.py) as the documentation says to do, I get the error
global name 'DonorFilter' is not defined
when I add the view. Here is the view.py:def donor_list(request): f = DonorFilter(request.GET, queryset=Donor.objects.all()) return render_to_response('donations/donor_list', {'filter': f})
That means I need to import the function I created in filters.py? So I add
from donations.filters import DonorFilter
to the top of my view. Then the error is'module' object has no attribute 'FilterSet'
I can see the FilterSet class in the filters.py file installed in my virtualenv
I noticed there is more development on django-filter, the https://github.com/alex/django-filter page goes up to v0.9.2, but pip installs 0.1.0. Should I be installing it another way (other than pip)?
I'm very new at this and appreciate any help!
score:68
My pip version was old, really old. 1.5.6 When I installed my virtual environment it just worked, so I didn't question. Lesson learned! Here is what I did in case it helps someone else...
In the virtual environment, I installed pip as described in the docs:
https://pip.pypa.io/en/stable/installing.html
python get-pip.py
This upgraded me to pip 6.1.1
pip install django-filter
pip freeze > requirements.txt
Reading requirements.txt showed I had
django-filter==0.9.2
django-filters==0.1.0
So I uninstalled the older version with pip uninstall django-filters
notice the s on the older version but not on the new one
Really basic stuff but it really tripped me up. Thanks to anyone who took time to look into this!
Similar question
- Django + mod_wsgi + apache: ImportError at / No module named djproj.urls
- ImportError at / No module named quickstart in django rest framework
- ImportError No module named localflavor.us.forms in Django 1.7
- Django - ImportError at /blog. No module named urls
- django : ImportError No module named myapp.views.hometest
- google app engine (python): ImportError no module named django
- ImportError at / No module named 'wsgi' in django
- Django ImportError no module named
- django ImportError at /admin/ no module named todo
- django allauth ImportError at /admin/ No module named context_processors
score:0
Ensure its django_filters and not django-filters in settings.py. Also keep in find its not django-filter, its django-filters.
But to install it:
pip install django-filter
score:0
I removed django_filters
in the settings INSTALLED_APPS
. this is worked for me
Some more answer related to the same question
- django admin load error: ImportError at /admin/login/ No module named backends
- Django ImportError No module named 'catalog.context_processors'
- Django - importError at /blog. (No module named urls)
- django Error : Caught ImportError while rendering: No module named comments
- Django - ImportError : no module named django.core.wsgi
- django import error - No module named core.management
- Django Rest Framework -- no module named rest_framework
- Django - "no module named django.core.management"
- Django import error - no module named django.conf.urls.defaults
- "No module named simple" error in Django
score:0
I also experienced the same problem but i realized its because i had installed django-filter when am in the virtual environment. I tried installing django-filter at the same directory without activating the virtual environment and it worked
I used pip install django-filter
score:1
We install it using: pip install django-filter
or in case you are using a virtual environment like pipenv, use pipenv install django-filter .
the above install, adds the latest version of django-filter. Add "==version" to specify the version ( say 0.11.0) you need
In the settings.py under app, ensure it's 'django_filters',
INSTALLED_APPS = [
# ...
'django_filters',
]
Related question
- Running django tutorial tests fail - No module named polls.tests
- No module named 'polls.apps.PollsConfigdjango'; Django project tutorial 2
- No module named django but it is installed
- ImportError: No module named django.core.handlers.wsgi in install django mod_wsgi config on apache
- Import Error: No module named django
- Django Shell No module named settings
- Getting stuck at Django error: No module named registration
- Django Import Error: No module named apps
- Python Django : No module named security
- Django - No module named _sqlite3
score:1
I tried all of the above answers and none of them worked for me. I later learnt that the pip script is not installing modules for the interpreter that the python command is using.
SOLUTION:
python -m pip install django-filter
score:3
I had a similar issue using django 1.7, djangorestframework==3.2.0 and latest django-filter==0.13.0:
Using DjangoFilterBackend, but django-filter is not installed
cannot import name Expression
I finally fixed it by downgrading django-filter to 0.11.
Now pip freeze looks like this and its working:
Django==1.7
django-filter==0.11.0
djangorestframework==3.2.0
score:3
I changed from django_filter
to django_filters
in installed apps and it was okay.
score:12
I also encountered this issue installing django-filter==2.2.0
This was my Django version:
Django [required: >=1.11, installed: 2.2]
settings.py:
INSTALLED_APPS = [
# ...
'django_filter',
]
This is the correct installation:
pipenv install django-filter
Hope it helps.
score:13
I also had the same issue. Even after installing django-filters
I couldn't import it
ImportError: No module named django_filters
The Django version I'm using is 1.8 and python version is 2.7.x
Solution is to install djangorestframework-filters
pip install djangorestframework-filters
The names are very confusing.
However django-rest-framework-filters
is an extension to Django REST framework and Django filter that makes it easy to filter across relationships while Django-filter
is a reusable Django application allowing users to declaratively add dynamic QuerySet filtering from URL parameters.
Credit To: stackoverflow.com
More Query from same tag
- where to place .htaccess on elastic beanstalk python
- Postgresql operator class "varchar_pattern_ops" does not accept data type integer
- In Django Admin, I want to change how foreign keys are displayed in a Many-Many Relationship admin widget
- Can a simple MD5 hash converted to a django password?
- No Product matches the given query. Django
- Django REST API browser page not showing
- how to reply email from django default admin to the contact?
- Django Channels JWT Authentication
- How to get the number of items in Page object?
- Django forms - best practice to set initial values in __init__() method
- Best way to store web page content in database using Django and a single template for web pages
- customizing functionality of field lookups for custom Django model fields
- Django admin form process file upload: 'InMemoryUploadedFile' object has no attribute 'width'
- Way to allow for duplicate many-to-many entries in Python/Django
- Django breaks on urls containing "logout"