问题标签 [pylance]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
26512 浏览

python - 在 Windows 10 Powershell 上使用 Python 3.9.2 在 VS Code 中的源 Pylance 无法解析/无法解析导入

我的 Flask App 服务器正在运行,但我有三个无法解析的导入。 未解决的进口

我努力了:

  1. 单独重新安装导入
  2. 重新安装 requirements.txt
  3. 我为 VSCode 工作区配置了一个指向我的项目文件夹的额外路径(我的项目文件夹的根目录中现在有一个 .vscode 文件,以前没有)
  4. 我在 VSCode 中更新了我的 venv 路径设置

这是我的文件结构:

不幸的是,这些事情都没有解决我的进口问题,我的路线仍然无法正常工作。有什么想法/建议吗?

0 投票
1 回答
445 浏览

python - 选择 conda 作为 python 解释器时 pylance `unresolved import` 错误

我正在使用 vscode 并使用 pylance 在 python 中进行 linting 尝试导入 restframework 时出现错误:

Import "rest_framework.decorators" could not be resolved

当我选择 conda 环境作为我的 python 解释器时出现此错误,但如果我选择默认 python 路径作为我的解释器,我不会收到此错误。

为什么只有当我选择 conda 环境作为解释器路径时才会出现此类错误

请通过回答帮助我。

0 投票
3 回答
107 浏览

python - 如何使用 VSCode 中的自动完成功能防止 Python 的对象名称重复?

我正在使用 VSCode 在 Jupyter Notebook 中编写 Python 代码。安装的相关扩展是PythonPylanceJupyter。当我尝试使用选项卡自动完成任何对象的方法名称时,就会出现问题。例如,如果建议框如下所示:

在此处输入图像描述

然后我按 Tab 接受建议,database重复对象名称,即代码看起来像dataset.dataset.as_numpy_iterator而不是dataset.as_numpy_iterator. 如何删除此对象名称重复?谢谢!

0 投票
2 回答
103 浏览

python - 有没有办法在 VSCode/pylance 中将 python 函数标记为不完整/未实现?

我对 python 比较陌生,使用 VSCode 进行 python 开发。据我所知,VSCode 正在使用一个名为“pylance”的扩展来处理 python 支持功能,例如在您编写时检测代码中的错误。

在我使用的最后一种语言(Scala)中,有一个很棒的小表达式???可以用来将方法标记为不完整/未实现,这样它就不会在编译器或 IDE 中产生任何错误,并且只会抛出一个如果在运行时遇到异常。

python中是否有任何等价物,特别是pylance可以理解的?这个想法是有一个未实现的函数,或者一个返回类型提示不满足的函数,因为它不完整,但这不会引发任何错误,这会使我更难找到部分的问题'实际上正在努力。

显然这不是关键,只是偏好问题,但最好保持信噪比低!谢谢

0 投票
1 回答
239 浏览

python - 来自 google-cloud-sdk 的 Pylance 问题

重新安装 Windows 后,Pylance 显示 Google Cloud SDK 错误。

第一个问题,由导入:

导入“google.appengine.ext”无法解析Pylance (reportMissingImports)

我需要为 Cloud SDK 添加额外路径。我已经看到/尝试了各种解决方案并发现这很有效:

当前问题,使用该库的位置;到处都是代码。

“模型”不是模块Pylance 的已知成员(reportGeneralTypeIssues)

“StringProperty”不是模块Pylance 的已知成员(reportGeneralTypeIssues)

我看不到前进的方向。

0 投票
1 回答
68 浏览

python - Intellisense 无法将 sklearn 返回的变量识别为数组类型

(我的环境是使用pylance的vs代码)

例如,从数组返回train_test_split()LinearRegression.predict()不被识别为数组并且不提供任何自动完成建议。在输入 google colab 和 spyder 后my_returned_array.,我得到一长串可用的数组函数,但在 带有 pylance 的 VS 代码中我什么也没得到。

我需要做一些额外的配置还是需要使用其他扩展?

0 投票
0 回答
144 浏览

python - visual studio code with pylance cannot resolve imports while using docker

I set up visual studio code to use a docker instance provided to me. For some reason pylance cannot locate some of my imports even though I added the import path in the settings.json for user, container and workspace. I am wondering if anybody has experience with that and can help me. Adding some pictures that shows the issue. In particular i am interested in pylance locating the cocotb library. Thanks for any help Amish

enter image description here

enter image description here

0 投票
2 回答
179 浏览

python - 如果有多个可能的返回值,pyright 是否应该根据传递的参数自动推断正确的返回值?

我有以下功能:

我对它的理解是,如果我None作为参数传递,我总是得到None作为返回值。另一方面,etree._Elementas 参数总是会导致str返回。

如果我使用 pylance 在 vscode 中编写以下内容(它在后台使用 pyright):

在这种情况下,我得到类型提示(variable) variable: str | None。我希望 pylance 知道该变量应该是 type str。我在监督什么吗?这可能是一个错误吗?

如果这按预期工作:是否有可能手动告诉 pylance“只要这个函数得到 aetree._Element它就会返回 astr并且每当我通过None它时它就会返回None”?

0 投票
0 回答
71 浏览

python - 导入“unittest2”无法解决 Pylance

我在树莓派的 Python 代码中遇到了这个错误。

0 投票
1 回答
52 浏览

python - Visual Studio 代码报告 docopt 导入错误,而 bash 终端没有问题

刚刚安装了关于我在 main.py 中的代码的扩展 ms-python.python Visual Studio 代码报告

}

为什么我可以正常导入模块而 vscode 扩展ms-python.python不能?

如果我跑python