Mac下VSCode运行Python提示zsh: command not found: python的解决求助
解决VSCode右上角运行按钮无法执行Python文件的问题
问题核心是Mac系统默认没有python命令(仅提供python3),但VSCode右上角运行按钮调用的是python命令,导致找不到;而右键运行使用的是完整路径的python3,所以能正常执行。以下是具体解决方法:
方法一:指定VSCode的Python解释器
- 打开VSCode,按下
Cmd+Shift+P唤起命令面板 - 输入
Python: Select Interpreter,选择路径为/usr/local/bin/python3的解释器 - 重新点击右上角运行按钮测试
方法二:修改launch.json运行配置
如果方法一无效,手动修改运行配置文件:
- 点击左侧「运行和调试」图标(或按
Cmd+Shift+D) - 点击「创建launch.json文件」,选择Python环境
- 在生成的
launch.json中,找到对应配置项,添加或修改python字段为python3或完整路径:{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "python": "/usr/local/bin/python3" } ] } - 保存后重新运行测试
方法三:全局创建python软链接(可选)
通过终端给python3创建名为python的软链接,让系统识别python命令:
ln -s /usr/local/bin/python3 /usr/local/bin/python
执行后,VSCode默认的python命令就能指向python3,无需修改VSCode配置
内容的提问来源于stack exchange,提问作者Gareth Morton
相关产品推荐
相关产品推荐

