【发布时间】:2021-06-22 15:05:00
【问题描述】:
def time_stats(df):
start_time = time.time()
当我在 VS Code 中运行此代码时,它运行良好,但是“时间”带有下划线:
如果我将鼠标悬停在那里,我会看到来自 PyLance 的错误消息:
"time" is not defined: UndefinedVariable
我在文件开头做了import time,但在https://docs.python.org/3/library/time.html#time.time 中找不到线索。
我想这不是一个大问题,但由于我正在学习,我很想得到一些建议,这样我就可以从一开始就避免坏习惯。
【问题讨论】:
-
听起来像是 VS Code 或 PyLance 的问题,而不是 Python。您可能希望将
VS Code和/或 [pylance] 标签添加到您的问题中,以便选择这些标签的人更容易找到您的问题。 -
显然 PyLance 有很多问题,谷歌自动完成 "pylance no" 到 "pylance not detection imports"
-
这能回答你的问题吗? VSCode settings for Pylance (并尝试将您的 python libs 目录添加到列表中?)
-
谢谢大家!我很高兴听到这可能与我的代码无关。
-
@maud 你能正确运行你的代码吗?你能启用 flake8 linter 吗?你可以在你的 settings.json 文件中添加这个: "python.linting.flake8Enabled": true,
标签: python visual-studio-code pylance