简体   繁体   中英

I can't import dotenv from python-dotenv

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?

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.

如果您有 1 个以上的 Python 版本,请尝试更改您的 Python 版本。我遇到了 3.10.0 的问题,我将其更改为 3.9.6。

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

I had a similar problem working with the virtual environment. I found my solution in this link: https://stackoverflow.com/a/59832029/18736200 . Everything works fine now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM