title: ImportError: cannot import name 'UserSerializer' from 'user.serializers'
body: <p>I started a project in django and I am having problems with imports. I think the problem is caused by cyclical imports. I have changed the code in many ways, but I cannot solve it.</p>
  <p>The error:</p>
  <pre class="lang-sh prettyprint-override"><code>  File &quot;/home/Workspace/vesta/vesta/urls.py&quot;, line 8, in &lt;module&gt;
      from user.api import UserModelViewSet
    File &quot;/home/Workspace/vesta/user/api.py&quot;, line 8, in &lt;module&gt;
      from user.serializers import UserSerializer
    File &quot;/home/Workspace/vesta/user/serializers.py&quot;, line 5, in &lt;module&gt;
      from core.serializers import (UUIDSerializer)
    File &quot;/mhome/Workspace/vesta/core/serializers.py&quot;, line 2, in &lt;module&gt;
      from user.serializers import UserSerializer
  ImportError: cannot import name 'UserSerializer' from 'user.serializers' (/home/Workspace/vesta/user/serializers.py)
  </code></pre>
  <p>And the code:</p>
  <p><strong>vesta/vesta/urls.py</strong></p>
  <pre><code>from django.contrib import admin
  from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  from django.urls import include, re_path
  from rest_framework.routers import DefaultRouter
  from rest_framework_simplejwt.views import (TokenObtainPairView, TokenRefreshView, TokenVerifyView)
  
  from core.api.schemas.schema_view import schema_view
  from user.api import UserModelViewSet
  
  router = DefaultRouter()
  router.register(r'user', UserModelViewSet, basename='user')
  
  urlpatterns = [
      # API documentation and playground
      re_path(r'^api-doc/$', schema_view.with_ui('redoc', cache_timeout=0), name='api-doc'),
      re_path(r'^api-playground(?P&lt;format&gt;\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0),
              name='api-playground-json'),
      re_path(r'^api-playground/$', schema_view.with_ui('swagger', cache_timeout=0), name='api-playground-ui'),
  
      # Admin
      re_path(r'admin/', admin.site.urls),
  
      # Authentication token
      re_path(r'auth/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
      re_path(r'auth/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
      re_path(r'auth/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
  
      # API
      re_path(r'', include(router.urls))
  ]
  
  urlpatterns += staticfiles_urlpatterns()
  
  </code></pre>
  <p><strong>vesta/user/api.py</strong></p>
  <pre class="lang-py prettyprint-override"><code>from django.utils.decorators import method_decorator
  from drf_yasg.utils import swagger_auto_schema
  from rest_framework import mixins
  
  from core.api.parameters import query_parameter
  from core.viewsets import BaseModelViewSet
  from user.models import User
  from user.serializers import UserSerializer
  
  
  @method_decorator(name='retrieve', decorator=swagger_auto_schema(manual_parameters=[query_parameter]))
  class UserModelViewSet(mixins.RetrieveModelMixin,
                         BaseModelViewSet):
      lookup_field = 'email'
      lookup_value_regex = r'[\w.@+-]+'
  
      action_serializers = {
          'retrieve': UserSerializer
      }
  
      def get_queryset(self):
          return User.objects.filter(id=self.request.user.id)
  
  </code></pre>
  <p><strong>vesta/user/serializers.py</strong></p>
  <pre class="lang-py prettyprint-override"><code>from django_restql.mixins import DynamicFieldsMixin
  from rest_framework import serializers
  
  from core.serializers import ModificationSerializer
  from core.serializers import (UUIDSerializer)
  from group.serializers import GroupSerializer
  from user.models import User
  
  
  class UserSerializer(DynamicFieldsMixin, serializers.HyperlinkedModelSerializer, UUIDSerializer,
                       ModificationSerializer):
      groups = GroupSerializer(many=True)
  
      class Meta(UUIDSerializer.Meta, ModificationSerializer.Meta):
          model = User
          fields = UUIDSerializer.Meta.fields + ModificationSerializer.Meta.fields + ['email', 'first_name', 'last_name',
                                                                                      'groups']
  
  </code></pre>
  <p><strong>vesta/core/serializers.py</strong></p>
  <pre class="lang-py prettyprint-override"><code>from rest_framework.serializers import BaseSerializer
  from user.serializers import UserSerializer
  
  
  class UUIDSerializer(BaseSerializer):
      class Meta:
          fields = ['uuid']
  
  
  class ModificationSerializer(BaseSerializer):
      modified_by = UserSerializer()
  
      class Meta:
          fields = ['modified_at', 'modified_by']
  
  </code></pre>
  <p><strong>Tree</strong></p>
  <pre class="lang-sh prettyprint-override"><code>vesta
  ├── core
  │   ├── api
  │   │   ├── __init__.py
  │   │   ├── parameters
  │   │   │   ├── __init__.py
  │   │   │   └── query_parameter.py
  │   │   └── schemas
  │   │       ├── __init__.py
  │   │       └── schema_view.py
  │   ├── apps.py
  │   ├── __init__.py
  │   ├── models
  │   │   ├── creation_model.py
  │   │   ├── __init__.py
  │   │   ├── modification_model.py
  │   │   └── uuid_model.py
  │   ├── serializers.py  # &lt;---------------------- Here (UseSerializer)
  │   └── viewsets
  │       ├── base_model_view_set.py
  │       └── __init__.py
  ├── group
  │   ├── admin
  │   │   ├── group_admin.py
  │   │   └── __init__.py
  │   ├── apps.py
  │   ├── __init__.py
  │   ├── models
  │   │   ├── group_model.py
  │   │   └── __init__.py
  │   └── serializers
  │       ├── group_serializer.py
  │       └── __init__.py
  ├── manage.py
  ├── requirements.txt
  ├── user
  │   ├── admin
  │   │   ├── __init__.py
  │   │   └── user_admin.py
  │   ├── api.py  # &lt;---------------------- Here (UseSerializer)
  │   ├── apps.py
  │   ├── __init__.py
  │   ├── managers
  │   │   ├── __init__.py
  │   │   └── user_manager.py
  │   ├── models
  │   │   ├── __init__.py
  │   │   └── user_model.py
  │   └── serializers.py
  └── vesta
      ├── asgi.py
      ├── __init__.py
      ├── settings
      │   ├── base.py
      │   ├── __init__.py
      │   ├── local.py
      │   └── third_party
      │       ├── __init__.py
      │       ├── rest_framework.py
      │       └── swagger.py
      ├── urls.py
      └── wsgi.py
  </code></pre>
  <p>I think that the problem is between the file <strong>vesta/user/api.py</strong> and <strong>vesta/core/serializers.py</strong>.</p>
  <p>How can i solve that?</p>
  <p>Thank you very much :)</p>