no module named "dotenv" in visual studio code

Question:

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

Asked By: Heidar-An

||

Answers:

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 (libsite-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.

Answered By: Jill Cheng

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

Answered By: Delabi

I deactivated my virtual machine and re-activated it and it worked!

Answered By: Jack_Lynch