Pyright在Virtualenv中没有从库中找到进口
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在项目root中创建一个
pyrightConfig.json
file> file> file> file> file> toml externative),并在其中添加两个字段,其中
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 itwhere the
venvPath
andvenv
are both needed and they will eventually be concatenated as the full path to your specific env namedvenv
.See also: GitHub issue thread, GitHub Pyright sample config.