简体   繁体   English

VSCode ModuleNotFoundError:终端中没有名为 <...> 的模块

[英]VSCode ModuleNotFoundError: No module named <...> in Terminal

When I try to import the MWE below from the Terminal in VSCode, I get当我尝试从 VSCode 中的终端导入下面的 MWE 时,我得到

ModuleNotFoundError: No module named 'tqdm'

temp.py:临时文件:

import tqdm

print('hello')

Here is my Terminal session:这是我的终端 session:

(mainenv) Larrys-MBP-5:Desktop larry$ python3
Python 3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:39:15) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import temp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/larry/Desktop/temp.py", line 1, in <module>
    import tqdm
ModuleNotFoundError: No module named 'tqdm'

I'm using a conda environment called mainenv .我正在使用一个名为mainenv的 conda 环境。 I can confirm (via conda list ) that tqdm is installed:我可以确认(通过 conda conda listtqdm已安装:

在此处输入图像描述

I can also confirm that VSCode is using mainenv as the interpreter:我还可以确认 VSCode 使用mainenv作为解释器:

在此处输入图像描述

I get the same error if I replace tqdm with other packages too, like jsonpickle and tabulate .如果我也将tqdm替换为其他包,例如jsonpickletabulate ,我会得到同样的错误。 But if I replace it with numpy or networkx , for example, it works fine.但是,如果我用numpynetworkx替换它,例如,它工作正常。

What's going on here?这里发生了什么?

Did You Use Pip Or npm?您使用的是 Pip 还是 npm? When I try to use npm in vscode for python modules it doesn't work, it works for me when I use pip though.当我尝试在 vscode 中为 python 模块使用 npm 时它不起作用,但当我使用 pip 时它对我有用。

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

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