I'm getting this error in VS Code:
error: "Unable to import 'rest_framework'pylint(import-error)"
I've installed djangorestframework with pip in my virtual environment. I activated the environment before installing it but when I try to import django_rest_framework in my app "book", it says that can't import it. I've added the rest framework in my installed apps but I don't know which is the problem.
I'm working with django 2.1.5 and djangorestframework 3.9.3 and python 3.6.7 and pip3 19.1.1 I've checked with pip freeze and it's installed. The virtual environment is activated.
What could be the problem? I opened in PyCharm but i got the same error
Code from I'm getting the importation error in my serializer.py file that is in my app called "book"
from rest_framework import viewsets
from .models import Book
from .serializer import BookSerializer
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'book',
]
I think you are not using your virtual environment in VSCode. You can update your workspace settings like this:
{
"python.defaultInterpreterPath": "/path/to/your/venv/bin/python",
}
Or you can choose an environment from vscode.
Did you install proper package ? The syntax for installing Django Rest Framework is:
pip install djangorestframework
which is confusing sometimes becouse in INSTALLED_APPS you type 'rest_framewor'. Check if you installed djangorestframework
not for example: django-rest-framework
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With