Pyright在Virtualenv中没有从库中找到进口

发布于 2025-02-10 06:19:34 字数 2302 浏览 3 评论 0原文

Pyright报告既缺少导入(无法解决)和常规类型错误(未知导入符号)。这些库都存在 - 我可以在没有错误的情况下以ipython运行代码。我正在使用诗歌来管理我的虚拟环境。我的VENV很活跃。

virtualenv信息:

Virtualenv
Python:         3.10.1
Implementation: CPython
Path:           /Users/jayed/Library/Caches/pypoetry/virtualenvs/create-cluster-PmxHvHbg-py3.10
Valid:          True

我的pyrightconfig.json

{
  "venvPath": "/Users/jayed/Library/Caches/pypoetry/virtualenvs",
  "venv": "create-cluster-PmxHvHbg-py3.10"
}

pyright输出

Loading configuration file at /Users/jayed/repos/create_cluster/pyrightconfig.json
Assuming Python version 3.10
Assuming Python platform Darwin
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
stubPath /Users/jayed/repos/create_cluster/typings is not a valid directory.
Searching for source files
Found 1 source file
pyright 1.1.255
/Users/jayed/repos/create_cluster/create_cluster/create_cluster.py
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:49:6 - error: Import "google.iam.v1" could not be resolved (reportMissingImports)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:50:6 - error: Import "google.iam.v1.policy_pb2" could not be resolved (reportMissingImports)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:43:26 - error: "assuredworkloads_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:44:26 - error: "billing_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:45:26 - error: "kms_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:46:26 - error: "resourcemanager_v3" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:47:26 - error: "service_usage_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:48:26 - error: "storage" is unknown import symbol (reportGeneralTypeIssues)
8 errors, 0 warnings, 0 informations
Completed in 1.912sec

pyright reports both missing imports (could not be resolved) and general type errors (unknown import symbol). These libraries all exist -- I can run the code in ipython without errors. I'm using poetry to manage my virtual environment. My venv is active.

The virtualenv info:

Virtualenv
Python:         3.10.1
Implementation: CPython
Path:           /Users/jayed/Library/Caches/pypoetry/virtualenvs/create-cluster-PmxHvHbg-py3.10
Valid:          True

My pyrightconfig.json

{
  "venvPath": "/Users/jayed/Library/Caches/pypoetry/virtualenvs",
  "venv": "create-cluster-PmxHvHbg-py3.10"
}

pyright output

Loading configuration file at /Users/jayed/repos/create_cluster/pyrightconfig.json
Assuming Python version 3.10
Assuming Python platform Darwin
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
stubPath /Users/jayed/repos/create_cluster/typings is not a valid directory.
Searching for source files
Found 1 source file
pyright 1.1.255
/Users/jayed/repos/create_cluster/create_cluster/create_cluster.py
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:49:6 - error: Import "google.iam.v1" could not be resolved (reportMissingImports)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:50:6 - error: Import "google.iam.v1.policy_pb2" could not be resolved (reportMissingImports)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:43:26 - error: "assuredworkloads_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:44:26 - error: "billing_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:45:26 - error: "kms_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:46:26 - error: "resourcemanager_v3" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:47:26 - error: "service_usage_v1" is unknown import symbol (reportGeneralTypeIssues)
  /Users/jayed/repos/create_cluster/create_cluster/create_cluster.py:48:26 - error: "storage" is unknown import symbol (reportGeneralTypeIssues)
8 errors, 0 warnings, 0 informations
Completed in 1.912sec

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖树树初阳… 2025-02-17 06:19:34

您可以在项目root中创建一个pyrightConfig.json file> file> file> file> file> toml externative),并在其中添加两个字段

{
  "venvPath": "ABSOLUTE_PATH_TO_YOUR_ENVS",
  "venv": "ENV_NAME"
}

,其中venvpath and code> code> venv 两者都需要,最终它们将被串联为您特定env的完整路径,名为venv

另请参见: github essue thread github pyright样本config

You can create a pyrightconfig.json file (or toml alternative) in your project root and add the two fields to it

{
  "venvPath": "ABSOLUTE_PATH_TO_YOUR_ENVS",
  "venv": "ENV_NAME"
}

where the venvPath and venv are both needed and they will eventually be concatenated as the full path to your specific env named venv.

See also: GitHub issue thread, GitHub Pyright sample config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文