問題:
Mac升級Monterey后,Cocos 2.4.x無法構(gòu)建原生平臺,構(gòu)建時報錯:
Build Failed: Error: Can't find python, please install python or check your environment
原因:
Mac原本自帶2.7版本的python,但是升級Monterey后,系統(tǒng)刪除了python2,默認(rèn)自帶python3,但是Cocos構(gòu)建只支持python2,所以報錯
解決:
打開終端,按以下指令操作:
1.安裝pyenv命名
brew install pyenv
2.配置pyenv初始化指令
//如果沒有.zprofile文件,則先創(chuàng)建一個
touch ~/.zprofile
open -e ~/.zprofile
在文件中插入以下指令
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
3.終端中查看可安裝python版本
pyenv install --list
4.安裝Python2
pyenv install 2.7.18
5.替換全局的Python版本
pyenv global 2.7.18
6.終端輸入:
open ~/.bash_profile
將以下內(nèi)容添加到bash_profile中:
exprot PATH="$(pyenv root)/shims:${PATH}"
保存后,終端輸入:
source ~/.bash_profile
輸入:
open ~/.zshrc
將source ~/.bash_profile添加到zshrc文件中,保存后,終端輸入:
source ~/.zshrc
7.輸入python,查看顯示的python版本:
***@***-MBP ~ % python
Python 2.7.18 (default, Mar 23 2023, 14:50:58)
[GCC Apple LLVM 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
8.打開Cocos,點(diǎn)擊構(gòu)建,運(yùn)行成功