Mac zsh环境下which python路径异常与node-gyp报错问题
问题:修复macOS下
which python返回路径及node-gyp找不到Python的问题 目标
让which python命令返回/usr/bin/python2.7,且该路径对应的可执行文件能正常运行。
当前问题
which python当前错误返回:/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonecho $PYTHON能正确返回/usr/bin/python2.7,但which命令结果未符合预期- 使用zsh shell,已执行
source ~/.zshrc并重启电脑,问题依旧
环境信息
系统PATH输出
/Users/myname/.nvm/versions/node/v16.16.0/bin:/usr/bin:/Users/myname/.sdkman/candidates/java/current/bin:/Users/myname/.nvm/versions/node/v16.16.0/bin:/usr/bin/python2.7:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myname/tools/apache-maven-3.8.1/bin:/Users/myname/tools/apache-maven-3.8.1/bin
.zshrc中的相关配置
export PYTHON="/usr/bin/python2.7" export PATH="$PYTHON:$PATH"
.zshrc完整内容
export PYTHON="/usr/bin/python2.7" export PATH="$PYTHON:$PATH" # Believe only the above 2 lines is relevant. Leaving the rest in just in case. export M2_HOME=/Users/name/tools/apache-maven-3.8.1 export PATH=$PATH:$M2_HOME/bin export NODEJS_ORG_MIRROR=https://myserver-proxy export NVM_NODEJS_ORG_MIRROR=$NODEJS_ORG_MIRROR export NODE_ENV=development export NODE_CERTS="/Users/name/certs.pem" export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion export ZSH="$HOME/.oh-my-zsh" ZSH_THEME="robbyrussell" plugins=(git) source $ZSH/oh-my-zsh.sh #THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!! export SDKMAN_DIR="$HOME/.sdkman" [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh" export JETBRAINS_LICENSE_SERVER="http://jetbrains.something.com:443"
更新排查信息
执行ls -lah /usr/bin/python2.7返回:
ls: /usr/bin/python2.7: No such file or directory
但进入/usr/bin目录后,输入python2.7可以正常打开交互式Python shell。
触发问题的场景
安装Node项目时出现node-gyp报错,具体信息如下:
gyp info using node-gyp@3.8.0 gyp info using node@14.18.2 | darwin | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "/usr/bin/python2.7" in the PATH gyp verb `which` failed Error: not found: /usr/bin/python2.7 gyp verb `which` failed at getNotFoundError (/Users/name/projects/fe/aa/node_modules/which/which.js:13:12) gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "/usr/bin/python2.7", you can set the PYTHON env variable.
疑问
请问我遗漏了什么配置?
内容的提问来源于stack exchange,提问作者karvai
相关产品推荐
相关产品推荐

