VSCode Python调试器与Pylance无法识别已安装的snowflake-connector-python包
VSCode调试器与Pylance无法识别虚拟环境中安装的snowflake-connector-python包
我在虚拟环境中执行命令 pip install snowflake-connector-python[pandas]==2.7.6 安装了snowflake-connector-python包,激活虚拟环境后在命令行运行脚本完全正常。但将该虚拟环境设置为VSCode的Python解释器后,启动Python调试器时抛出以下异常:
ModuleNotFoundError: No module named 'snowflake.connector'
同时Pylance也无法识别这个包,但其他已安装的包都能正常被识别。我查过多个类似问题的解决方案,都没有效果。
编辑补充1
我在launch.json中添加了python参数指定虚拟环境的Python路径,配置如下:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "python": "${workspaceFolder}/MyVenv/Scripts/python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "args": [ "--env", "dev", "--argument" ], "envFile": "${workspaceFolder}/.env", } ] }
但问题依然存在。
编辑补充2
我尝试修改模块导入方式后,Pylance不再标记该包为未识别,但调试器仍会抛出上述错误。新旧导入方式如下:
旧导入方式:
新导入方式:
采用新方式后,Pylance不再高亮标记该包,但也没有将其识别为有效模块。
内容的提问来源于stack exchange,提问作者HuLu ViCa
相关产品推荐
相关产品推荐

