1

I can't import the rest_framework_simplejwt in my django project specifically in my urls.py. I downgrade django to 3.0 and djangorestframework to 3.10 and still didnt work. the console shows me

{
    "resource": "/c:/Dev/realest_estate2/backend/realest_estate/urls.py",
    "owner": "python",
    "code": "import-error",
    "severity": 8,
    "message": "Unable to import 'rest_framework_simplejwt.views'",
    "source": "pylint",
    "startLineNumber": 6,
    "startColumn": 1,
    "endLineNumber": 6,
    "endColumn": 1
}

this is what im importing.

from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)

This is my configuration in my settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'rest_framework',
    'accounts',
]
MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
REST_FRAMEWORK = {
  'DEFAULT_PERMISSION_CLASSES': [
    'rest_framework.permissions.IsAuthenticated'
  ],
  'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
  ]
}

and here is my pip freeze

asgiref==3.2.10
Django==3.0
django-cors-headers==3.4.0
djangorestframework==3.10.0
djangorestframework-simplejwt==4.4.0
Pillow==7.2.0
psycopg2==2.8.5
psycopg2-binary==2.8.5
PyJWT==1.7.1
pytz==2020.1
sqlparse==0.3.1

if you need more info please tell me and i will provide it. Thank you

Gabo
  • 51
  • 5

2 Answers2

0

It was the interpreter of python i was using... sorry

Gabo
  • 51
  • 5
0

To elaborate on the above comment that it was an interpreter issue (which for my case is correct and is what was causing my text editor (pycharm) to not recognize the imports - specifically drfsimple-jwt but the issue would extend to any other imports that I did not already have as part of the interpreter I was using in that project).

  1. Configure the project/interpreter correctly so your project installs are added to the project venv interpreter. In pycharm here's how you do it (link below). For my project I just went through doing this and the most simple way was to just start a new venv for the project with the python version you have downloaded to computer, assign that interpreter to your project, then re-install any existing requirements to the new interpreter. https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html#python_create_virtual_env

  2. If you don't want to do #1, which is recommended so that all future installs won't cause issues, then you can add the package directly to the interpreter. In pycharm this can be done like this - https://stackoverflow.com/a/72879305/12212178 The downside to that is you'll need to remember to do it each time manually after you install it to your projects and add it to requirements.txt.

blueblob26
  • 75
  • 9