简体   繁体   English

PYTHON-DOTENV:从 vscode fun 按钮运行时不起作用

[英]PYTHON-DOTENV: not working when running from vscode fun button

Hello I have a weird situation where I run my python code from VScode run button, which brings me into Python terminal in VScode, I hvae this error message.您好我有一个奇怪的情况,我从 VScode 运行按钮运行我的 python 代码,这使我进入 VScode 中的 Python 终端,我收到此错误消息。

ModuleNotFoundError: No module named 'dotenv' ModuleNotFoundError:没有名为“dotenv”的模块

But if I run the same code in a regular terminal in VScode not Python terminal, I can run the code no error regarding dotenv.但是,如果我在 VScode 的常规终端而不是 Python 终端中运行相同的代码,我可以运行代码而不会出现关于 dotenv 的错误。

Can you please explain why it is happening?你能解释一下为什么会这样吗?

thank you谢谢你

Next time, please provide more information, be more clear, and would be better to attach some pictures.下次请提供更多信息,更清楚,并附上一些图片。 Otherwise, it's hard to understand what's your mean, and the people hard to give you suitable suggestions.否则很难理解你的意思,人们也很难给你合适的建议。

I guess the problem you meet just because you run your code with a different environment.我猜你遇到的问题只是因为你在不同的环境中运行你的代码。 The environment which you run across the problem because you haven't installed the 'dotenv' package.您遇到问题的环境是因为您尚未安装“dotenv”package。 It looks like you had installed the package in your global python environment, but you haven't installed the package in your virtual environment.看起来您已经在全局 python 环境中安装了 package,但您尚未在虚拟环境中安装 package。 You can add this code in your python file to distinguish which python, which environment you are using:您可以在您的 python 文件中添加此代码,以区分您使用的环境是哪个 python:

import sys
print(sys.executable)

If I am right, then you just need to activate your virtual environment(Ctrl+Shift+`), and run the command "pip install dotenv".如果我是对的,那么您只需要激活您的虚拟环境(Ctrl+Shift+`),然后运行命令“pip install dotenv”。 Before install, you should check which pip you are using, through the command "pip --version".在安装之前,您应该通过命令“pip --version”检查您使用的是哪个 pip。 Be sure you had installed the package into your virtual environment.确保您已将 package 安装到您的虚拟环境中。

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

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