1 year ago

#64586

test-img

amonmcduul

importing module is not being resolved in env:venv environment

Im following a course about Django and making an API. Im using visual code

I have set up an env:venv environment. When i try to import rest_framework i get the message:

"Import "rest_framework" could not be resolved - Pylance

Even though the import is working and i can use the functionalities.

Im using the python interpreter available in the ENV environment

  • Python 3.10.1 64-bit ('env':venv)

when i set the interpreter to the local python path the import is resolved. So that fixes the problem. But i want to use the interpreter for the ENV environment because i think it should work this way.

If i am in my ENV environment and i query 'pip list' the module to be resolved is installed:

(env) C:\DjangoProjects\amonmcduul>pip list

Package Version


asgiref 3.4.1

distlib 0.3.4

Django 4.0.1

djangorestframework 3.13.1

djangorestframework-simplejwt 5.0.0

I have also pip installed the djangorestframework on my local computer, hense it works when i set the interpreter to my local python interpreter.

I dont know why the import wont resolve.. it says it isnt resolved but it does work though. How can i resolve the import? Or get rid of the message 'it can't be resolved'

Picture of the issue

I have set the import in my settings file:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'projects.apps.ProjectsConfig',
'users.apps.UsersConfig',

'rest_framework',

]

I have:

  • restarted the virtual environment
  • pip install the module again
  • changed interpreters (to local en back to virtual environment)

python

django

visual-studio-code

virtualenv

resolve

0 Answers

Your Answer

Accepted video resources