「fix」MacOS python 路径问题

2022-11-09T04:08:53Z

有一些npm包里面使用着python对应macos的旧路径, 而新版本的苹果系统不再内置2.*的python。 所以路径上/usr/bin/python会找不到程序。

SIP的限制,用户拥有写入权限比较麻烦。

Error: Can't find Python executable \"/usr/bin/python\", you can set the PYTHON env variable.

解决方案:

$ brew install pyenv

# Any modern version python should do. I don't think Python 2 is required any more.
$ pyenv install 3.10.3
$ pyenv global 3.10.3

# Add pyenv to your PATH so that you can reference python (not python3)
$ echo "export PATH=\"\${HOME}/.pyenv/shims:\${PATH}\"" >> ~/.zshrc

# open a new terminal window and confirm your pyenv version is mapped to python
$ which python
$ python --version

# Now try to re-run yarn install
$ yarn