“ModuleNotFoundError:在 PyCharm 中导入存根文件时没有名为 'stubs.profiler' 的模块”

问题描述 投票:0回答:1

在pycharm中,我尝试在py文件中导入存根文件(.pyi文件),但遇到错误“ModuleNotFoundError:没有名为'stubs.profiler'的模块”。

我的文件结构如下: enter image description here 在 profiler.py 中,我尝试使用“import stubs.profiler”来获取定义的类和函数,但遇到错误“ModuleNotFoundError:没有名为“stubs.profiler”的模块。 我的文件内容如下,VOP目录在代码目录下。 enter image description here 有人可以帮我吗?我花了很多时间,谢谢!

python pycharm stub pyi
1个回答
0
投票

您可以将“stubs”文件夹移动到主文件的当前工作目录,也可以通过在文件中写入以下代码来从任何路径运行所需的 .py 文件:

import sys
sys.path.append("Complete path to stubs folder")
import profiler
© www.soinside.com 2019 - 2024. All rights reserved.