no module named "dotenv" in visual studio code

9.4k views Asked by At

I have seen this question about 5 times before, I have tried every solution there, I have tried uninstalling python-dotenv, reinstalling it, using pip, pip3, using pip3 -m install..., I don't have "dotenv" (the one without python) by itself, I'm not using a virtual environment, i've tried switching to one and installing it but it still says that there is not module named "dotenv". I've also tried sudo pip3 install python-dotenv, yet I still face the same problem. Can someone help me please?

image

As you can see, when I try to use dotenv it doesn't work. I'm using flask if anyone wants to know.

Here is what the use looks like: image

3

There are 3 answers

0
Jill Cheng On BEST ANSWER

Based on the information you provide, please refer to the following:

  1. The location where the module is installed is not the python environment used by the current VS Code terminal.

    Please use the command "python --version" or "pip --version" to check whether the environment used by the VS Code terminal is the same as the one displayed in the lower left corner of VS Code:

    enter image description here

    (If their results are not the same, please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, and it will automatically enter the selected environment. If they are still different, please put the required python first in the python environment variable outside VS Code, and then reopen VS Code. )

  2. Please find the location of the module installation package (\lib\site-packages\), then move out or delete the folder "dotenv", and then reinstall the module.

    enter image description here

Check the installation of the module: (pip show python-dotenv)

enter image description here

Run:

enter image description here

Reference: Python environments in VS Code.

0
Laban Bwire On

Restarting my machine worked for me. I guess the restarting of the python virtual environment did it.

0
Nicolas On

For me, it worked by changing in the bottom right corner the Python version to the one I was using in the venv.

Image of the options I had