VSCode Pylance 在导入一些 TensorFlow 子模块时显示 [reportMissingImports]

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

我在vscode中使用conda环境。 TensorFlow已安装并可以正常使用。但是 Pylance 在某些导入的子模块或类等中显示

[reportMissingImports]
。例如,请参阅 https://i.stack.imgur.com/VcVOS.png

的屏幕截图

Pylance 无法解析波浪形的子模块,并且智能感知和自动补全无效,这对编码来说非常具有破坏性。相比之下,未弯曲的模块(如屏幕截图中的

tf
keras
)运行良好。

版本列表
python 3.10.13
TensorFlow 2.11.1
vscode 1.84.2
Pylance 2023.11.10

我已经确认我选择了正确的Python解释器。实际上,TensorFlow 在运行我的代码时运行良好。我注意到,当我输入

import tensorflow.python.
时,自动补全仅显示
keras
子模块。请参考截图https://i.stack.imgur.com/uqRn5.png

Pylance 是否被窃听,或者是否应该设置其他任何设置来确保 Pylance 按预期工作?

tensorflow visual-studio-code conda pylance
1个回答
0
投票

最后根据https://github.com/microsoft/pylance-release/issues/734找到了解决方案。 正如屏幕截图https://i.stack.imgur.com/yksy2.png,它确实工作得很好,正如我所期望的那样。

© www.soinside.com 2019 - 2024. All rights reserved.