IntelliJ运行服务时无法启动Python:找不到Python可执行文件(Mac环境)
解决IntelliJ中无法找到Python可执行文件的问题
错误信息
Error: Can't find Python executable "python", you can set the PYTHON env variable.
解决步骤
1. 确认Mac上Python的实际路径
打开终端,执行以下命令找到Python的安装路径:
which python3 # 或者 which python
通常会得到类似/usr/bin/python3或/usr/local/bin/python3的结果。
2. 方法一:设置PYTHON环境变量
- 临时生效:在终端执行(替换为你查到的路径):
之后重启IntelliJ即可。export PYTHON=/usr/bin/python3 - 永久生效:编辑shell配置文件(zsh用户编辑
~/.zshrc,bash用户编辑~/.bash_profile),添加一行:
保存后执行export PYTHON=/usr/bin/python3source ~/.zshrc(对应你的shell文件),再重启IntelliJ。
3. 方法二:直接在IntelliJ中配置Python解释器
- 打开IntelliJ,进入
File > Project Structure > SDKs - 点击
+按钮,选择Python SDK,定位到终端查到的Python路径并添加 - 确保项目模块的SDK设置为刚配置的Python解释器
4. 方法三:创建软链接适配python命令
如果系统中只有python3命令没有python,可以在终端执行(需要管理员权限):
sudo ln -s /usr/bin/python3 /usr/bin/python
这样系统会将python命令指向python3,IntelliJ就能识别到。
内容的提问来源于stack exchange,提问作者teja
相关产品推荐
相关产品推荐

