django-rest-framework-filters icon indicating copy to clipboard operation
django-rest-framework-filters copied to clipboard

ImportError: cannot import name 'six'

Open ibayeux opened this issue 4 years ago • 18 comments

A specified in Django 3.0 release note, django.utils.six is removed. In case you need it, it is advised to use pypi packages instead. can you update?

ibayeux avatar Jan 09 '20 02:01 ibayeux

"pip install --upgrade djangorestframework" update the Django rest framework to the latest will resolve the issue.

poojansmobio avatar May 07 '20 07:05 poojansmobio

Same happening here, upgrading djangorestframework didn't help

glothos avatar May 07 '20 21:05 glothos

Same happening here, upgrading djangorestframework didn't help

Which Django version you are using currently?

poojansmobio avatar May 08 '20 07:05 poojansmobio

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

YukinoHayakawa avatar May 23 '20 06:05 YukinoHayakawa

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

Having the same import problem. I tried your solution and it worked but do u know how stable it is for production?

eliezerp3 avatar Jun 02 '20 22:06 eliezerp3

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

Having the same import problem. I tried your solution and it worked but do u know how stable it is for production?

Unfortunately, I have no clear idea about that. I'm writing for tools for my personal use only. However, I'd suppose that a production-ready version won't be released with a dev label on it :)

YukinoHayakawa avatar Jun 05 '20 09:06 YukinoHayakawa

getting this error after placing configuration dict.

'DEFAULT_FILTER_BACKENDS': ( 'rest_framework_filters.backends.RestFrameworkFilterBackend', ),

Django version: 3.0.7 ImportError: Could not import 'rest_framework_filters.backends.RestFrameworkFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. ImportError: cannot import name 'six' from 'django.utils'

oguzhancelikarslan avatar Jun 10 '20 09:06 oguzhancelikarslan

I solved this by installing latest https://github.com/carltongibson/django-filter Since most of the stuff used by this library is merged back into django-filter I didn't have any problems using it. You just need to follow the installation step and change package imports paths.

Note that you need to uninstall this package before as it relies on an older version and you get this error ERROR: djangorestframework-filters 0.11.1 has requirement django-filter~=1.1, but you'll have django-filter 2.3.0 which is incompatible.

gmuj avatar Jul 31 '20 12:07 gmuj

Hey @poojansmobio do you have any updates on this? I'm happy to collaborate with you to solve this issue!

petrosschilling avatar Oct 21 '20 04:10 petrosschilling

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

poojansmobio avatar Oct 21 '20 04:10 poojansmobio

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

I did it but I get a dependency issue:

djangorestframework-jsonapi 3.2.0 requires djangorestframework<3.12,>=3.10, but you'll have djangorestframework 3.12.1 which is incompatible.

So basically I need to wait for a new version of djangorestframework-jsonapi before I can do this update.

petrosschilling avatar Oct 21 '20 05:10 petrosschilling

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

I did it but I get a dependency issue:

djangorestframework-jsonapi 3.2.0 requires djangorestframework<3.12,>=3.10, but you'll have djangorestframework 3.12.1 which is incompatible.

So basically I need to wait for a new version of djangorestframework-jsonapi before I can do this update.

In your case try downgrading it to djangorestframework==3.11.0 and check.

poojansmobio avatar Oct 21 '20 05:10 poojansmobio

I'm using JRF 3.11.1. Which save me from the conflicts.

The problem lies in the filterset.py file.

I checked the tag of version 0.11.1 and it still uses six.

filterset.py

from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
import copy

from django.db.models.constants import LOOKUP_SEP
from django.utils import six

from django_filters import filterset, rest_framework
from django_filters.utils import get_model_field

from . import filters
from . import utils

petrosschilling avatar Oct 21 '20 05:10 petrosschilling

I'm using JRF 3.11.1. Which save me from the conflicts.

The problem lies in the filterset.py file.

I checked the tag of version 0.11.1 and it still uses six.

filterset.py

from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
import copy

from django.db.models.constants import LOOKUP_SEP
from django.utils import six

from django_filters import filterset, rest_framework
from django_filters.utils import get_model_field

from . import filters
from . import utils

Replace from django.utils import six To import six

poojansmobio avatar Oct 21 '20 06:10 poojansmobio

Replace from django.utils import six To import six

Well that is not feasible, because in case i need to re-create my environment I will have to remember to change that import. Not only me but all other devs as well.

What I've done (for now) is to use the latest dev version (djangorestframework-filters==1.0.0.dev2) which will do for the time being.

The RelatedFilter is pretty good by the way. It is exactly what I was looking for. It doesn't pick up the override of the lookup_expr though:

class ClientAccountFilterSet(BaseFilterSet):
    individuals = RelatedMultipleFilter(IndividualFilterSet, queryset=Individual.objects.all())

class IndividualFilterSet(BaseFilterSet):
    first_name = CharFilter(lookup_expr="icontains")

    class Meta:
        model = Individual
        fields = [
            "first_name",
        ]

It still filter with exact not with icontains.

But that is another issue.

Thanks for your time and help! I might look into fixing this problem :)

petrosschilling avatar Oct 21 '20 06:10 petrosschilling

ModuleNotFoundError: No module named 'rest_framework_filtersstorages'

After trying

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

sinjihn-4th-valley avatar Jan 28 '21 02:01 sinjihn-4th-valley

ModuleNotFoundError: No module named 'rest_framework_filtersstorages'

After trying

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

You might have missed a comma (,) after 'rest_framework_filter'

ashish141199 avatar Jun 15 '21 11:06 ashish141199

@ashish141199 The latest pre-release is 1.0.0.dev2

hwalinga avatar Jun 15 '21 11:06 hwalinga