简体   繁体   中英

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.

ModuleNotFoundError: No module named '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.

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. It looks like you had installed the package in your global python environment, but you haven't installed the package in your virtual environment. You can add this code in your python file to distinguish which python, which environment you are using:

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". Before install, you should check which pip you are using, through the command "pip --version". Be sure you had installed the package into your virtual environment.

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