简体   繁体   English

导入“dotenv”无法解决

[英]import "dotenv" could not be resolved

I am making a program in python that I plan to host on github.我正在 python 中制作一个程序,我计划在 github 上托管。 I have a .env file containing an api token.我有一个.env文件,其中包含一个 api 令牌。 I tried to import it into my code like so:我试图将它导入到我的代码中,如下所示:

first i installed the python-dotenv library by typing pip install python-dotenv in the command prompt.首先,我通过在命令提示符下键入pip install python-dotenv来安装 python python-dotenv库。 python-dotenv shows when i type pip list . python-dotenv在我输入pip list时显示。

then in my code:然后在我的代码中:

import os
from dotenv import load_dotenv

load_dotenv()

example = os.getenv('TOKEN')

from dotenv import load_dotenv gives the error Import "dotenv" could not be resolved Pylancereport (MissingImports) and my code will not run. from dotenv import load_dotenv给出错误Import "dotenv" could not be resolved Pylancereport (MissingImports)并且我的代码将无法运行。 Is there anything i'm doing wrong?有什么我做错了吗? How can i fix it?我该如何解决?

It seems you have installed python-env , when you really wanted to install python-dotenv .当您真的想安装python-dotenv时,您似乎已经安装了python-env The former doesn't have the function you are trying to use on it's __init__.py file, that's why Pylancereport can't resolve it.前者没有您尝试在其__init__.py文件上使用的 function ,这就是Pylancereport无法解决它的原因。

Solution: Do a pip install python-dotenv .解决方案:执行pip install python-dotenv Execute your code again and it should work.再次执行您的代码,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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