Mac上pyenv的安裝及使用
安裝
brew update
brew install pyenv
報錯
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallowgit -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
那就執行這2句
還報錯
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 365476, done.
remote: Counting objects: 100% (365455/365455), done.
remote: Compressing objects: 100% (147319/147319), done.
fatal: The remote end hung up unexpectedly12 MiB | 9.00 KiB/s
fatal: early EOF
fatal: index-pack failed
需要換源
參考 https://blog.csdn.net/u013549582/article/details/120887331
## 更新 homebrew-cask(如果提示 No such file or directory 可以先跳過前三個命令)
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
# 更換源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 更新
git fetch --unshallow ## 更新 homebrew-core
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-core
# 更換源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 更新
git fetch --unshallow
再次執行
brew update
報錯
==> `brew cleanup` has not been run in 30 days, running now...
需要授權
sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
當然這里盡量縮小授權的范圍
然后執行
brew install pyenv
終于執行完了
可能需要多執行幾次
然后查看版本
pyenv versions
查看可以安裝的版本
pyenv install -l
安裝
pyenv install 3.8.8
然后報錯
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:LC_ALL = (unset),LANG = "en_CN.utf-8"are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
需要執行
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
然后重新執行pyenv install 3.8.8
還是報錯,見鬼了
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.8.tar.xz...
-> https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tar.xz
error: failed to download Python-3.8.8.tar.xzBUILD FAILED (OS X 13.2 using python-build 20180424)Results logged to /var/folders/jx/k9mhvtg96ggff_8_3c5bvqch0000gn/T/python-build.20240707210526.1843.logLast 10 log lines:
/var/folders/jx/k9mhvtg96ggff_8_3c5bvqch0000gn/T/python-build.20240707210526.1843 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
warning: xz not found; consider installing `xz` package
curl: (28) Failed to connect to www.python.org port 443 after 75025 ms: Couldn't connect to server
最后還是放棄了
https://www.python.org/downloads/macos/ 下載一個版本,手動安裝,哭死
換了版本之后,
python3 -V
pip3 --version