Skip to content
Advertisement

ModuleNotFoundError: No module named ‘rest_framework’ (tried many solutions but not working)

I have encountered this error.

ModuleNotFoundError: No module named 'rest_framework'

I have a virtual environment setted up and the rest framework is installed correctly.

When I run pip3.10 show djangoframework, I get

JavaScript

My interpreter is Python 3.10.8 which is the same version and it is for the virtual environment. my VSCode shows my interpreter as Python 3.10.8 ("TESTPY":venv) .Scriptspython.exe.

I also have included the rest_framework in the INSTALLED_APPS in the settings.py

JavaScript

Below is the full error I get.

JavaScript

I have googled to fix this issue so many times now that all the links are purple.. Anyone have any idea why this is happening? Thanks

Edit:

When I run pip list, this is what I get.

JavaScript

Advertisement

Answer

Maybe you should use just the python command instead of python3.

When you activate a virtualenv, what happens is that some shell binaries are added to your PATH. These binaries are typically python and pip, and maybe other binaries from other pip packages that are installed in the virtualenv.

So then when the virtualenv is activated, the python command will execute the python binary inside the virtualenv. But the python3 executable is not overriden, so when you execute that, you just get your system python3.

So try:

JavaScript

Or maybe you could even just do:

JavaScript

If that doesn’t work, it might be because the manage.py file needs to have execute permissions:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement