VS Code运行按钮无法执行Python程序(依赖导入异常)
确认VS Code选中的Python解释器为Anaconda环境
点击VS Code左下角状态栏显示的Python版本号,在弹出的环境列表中选择你安装的Anaconda对应的解释器(比如~/anaconda3/bin/python或Windows下的C:\Users\<你的用户名>\anaconda3\python.exe)。如果列表里没显示,选择「Enter interpreter path」手动定位到Anaconda安装目录下的Python执行文件。配置launch.json统一运行环境
点击运行按钮旁的「创建launch.json文件」并选择Python环境,确保配置文件中指定的解释器路径与Anaconda一致,同时将运行终端设置为集成终端,保证和手动执行命令的环境一致。示例配置:{ "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "python": "${command:python.interpreterPath}" } ] }排查PyCharm安装的Anaconda兼容性
PyCharm安装的Anaconda与官网版本功能无差异,仅默认关联PyCharm项目环境。只需确认Anaconda的路径已正确加入系统环境变量,且VS Code选中的解释器路径与终端中which python(Linux/macOS)或where python(Windows)输出的路径一致即可。验证依赖包的安装环境
在终端执行pip list,检查缺失的依赖包是否存在于当前Anaconda环境中。若依赖包安装在全局Python环境而非Anaconda环境,使用conda install <包名>或pip install <包名>在Anaconda环境中重新安装。
内容的提问来源于stack exchange,提问作者Kushinada

