3

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

Heidar-An
  • 89
  • 2
  • 11
  • 1
    who typed the line `from dotenv import .....`. You have to find out which Python interpreter executes `pip3` and which Python interpreter is used to execute the program – rioV8 Apr 18 '21 at 14:53
  • @rioV8 I did as part of my program, i'll update it to show what it looks like – Heidar-An Apr 18 '21 at 14:56
  • 1
    see my update comment, and never post images of text, it is hard to google search text in images – rioV8 Apr 18 '21 at 14:57
  • @rioV8 oh ok, thanks :) I'll look at your comment now – Heidar-An Apr 18 '21 at 15:12
  • Have you tried this https://stackoverflow.com/a/58944490/6244201 ? If it does not work, maybe consider your overall flask set up i.e case example, https://stackoverflow.com/a/59241409/6244201 – Gitau Harrison Apr 18 '21 at 18:28
  • I deactivated my virtual machine and re-activated it and it worked! – Jack_Lynch Nov 20 '22 at 05:52

2 Answers2

2

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.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
1

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

Laban Bwire
  • 81
  • 2
  • 7