2

Windows, Visual studio, django. I tried to install python-dotenv: https://pypi.org/project/python-dotenv/#getting-started.

But when I want to import this command, I get error: Import "dotenv" could not be resolvedPylancereportMissingImports.

I made such imports: (venv) PS C:\Users... pip3 install python-dotenv Requirement already satisfied: python-dotenv in c:\users...\venv\lib\site-packages (0.19.0).

But import doesn't work. What can be wrong?

4 Answers4

1

Try to change your Python version if you have more than 1. I got into trouble with the 3.10.0 and I changed it to 3.9.6.

Khailas R
  • 11
  • 1
1

I had the same problem. Check if the Python interpreter VSCode is using is the one from your virtual environment (e.g. myproject/venv/Scripts/python.exe). You can read more about it on the official VSCode docs.

montw
  • 85
  • 10
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31115214) – JayPeerachai Feb 24 '22 at 04:53
  • I deleted this answer a while ago, i dont know why it still appears. – montw Feb 24 '22 at 19:37
0

I solved this issue by adding the Python path to the settings.json file in VScode. Specifically, my .vscode folder contains "settings.json" where I added:

"python.pythonPath": "/path/to/python3"

Maybe it helps.

0

I think the problem stems from the python interpreter you are using.

  1. In VS Code, Go to View > Command Palette > Python: Select interpreter
  2. Switch from the global to the recommended one
  • Recommended: Python 3.11.3('venv':venv) .\venv\Scripts\python.exe
  • Global: Python 3.11.3 64 bit C:\Programs\Python3.11.3\python.exe

This worked for me.