简体   繁体   English

在 Mac OS Big Sur 上使用 pyenv 安装 python 3.6 时出现问题

[英]Problems installing python 3.6 with pyenv on Mac OS Big Sur

When installing Python 3.6.13 on my MacBook Air, OS Big Sur, using the command pyenv install 3.6.13 I get this error:在我的 MacBook Air、OS Big Sur 上安装 Python 3.6.13 时,使用命令 pyenv install 3.6.13 我收到此错误:

Installing Python-3.6.13...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 11.3 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/7j/0qtpb8vs1_s34ynv0f6rrs840000gn/T/python-build.20210304114832.65954
Results logged to /var/folders/7j/0qtpb8vs1_s34ynv0f6rrs840000gn/T/python-build.20210304114832.65954.log

Last 10 log lines:
./Modules/posixmodule.c:8210:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
./Modules/posixmodule.c:10432:5: warning: code will never be executed [-Wunreachable-code]
    Py_FatalError("abort() called from Python code didn't abort!");
    ^~~~~~~~~~~~~
1 warning and 1 error generated.
1 warning generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....

Any suggestions on how to fix this or another work around to install python 3.6.13 would be greatly appreciated.任何有关如何解决此问题或其他解决方法以安装 python 3.6.13 的建议将不胜感激。 I currently have python 3.8, but need 3.6 in order to run:我目前有 python 3.8,但需要 3.6 才能运行:

conda install -c deezer-research spleeter 

Thanks to jordanm, The solution was to follow https://github.com/pyenv/pyenv/issues/1740#issuecomment-738749988感谢乔丹,解决方案是遵循https://github.com/pyenv/pyenv/issues/1740#issuecomment-738749988

brew reinstall zlib bzip2

From people's comments (thanks to Lukasz Czerwinski and Alex Veksler) it seems many view this next step as optional (and even dangerous) and prefer to skip it;从人们的评论来看(感谢 Lukasz Czerwinski 和 Alex Veksler),似乎很多人认为下一步是可选的(甚至是危险的)并且更愿意跳过它; though, it's worth a try if nothing else is working:不过,如果没有其他工作,值得一试:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Whether you chose to skip the last step or not, continue by editing .zshrc or .bashrc using:无论您是否选择跳过最后一步,继续编辑.zshrc.bashrc使用:

nano ~/.zshrc or nano ~/.bashrc

and add:并添加:

export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="/usr/local/bin:$PATH"

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include"

after editing and saving that file, run:编辑并保存该文件后,运行:

. ~/.zshrc or . ~/.bashrc

Then run the command below to install (changing 3.6.0 for the desired patch)然后运行以下命令进行安装(将 3.6.0 更改为所需的补丁)

CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.6.0 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

The following steps finally worked for my MacBook Air M1 with Big Sur 11.6 .以下步骤最终适用于我的带有Big Sur 11.6MacBook Air M1

‼️ Please note that this instruction is for Rosetta 2 emulated x86 terminal. ‼️ 请注意,此说明适用于 Rosetta 2 仿真 x86 终端。

  1. Install brew:安装冲泡:

     arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install the recommended dependencies:安装推荐的依赖项:

     arch -x86_64 brew install openssl readline sqlite3 xz zlib
  3. Install Pyenv with brew:使用 brew 安装 Pyenv:

     arch -x86_64 brew install pyenv
  4. Configure your shell's environment (in my case zsh):配置你的 shell 环境(在我的例子中是 zsh):

     echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zshrc
  5. Restart the terminal.重启终端。

  6. Add environment variables (in my case the problem was with zlib and openssl):添加环境变量(在我的情况下,问题在于 zlib 和 openssl):

     export LDFLAGS="-L/usr/local/opt/zlib/lib" export CPPFLAGS="-I/usr/local/opt/zlib/include" export LDFLAGS="-L/usr/local/opt/openssl@3/lib" export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
  7. Install the required Python version with patch:安装所需的 Python 版本和补丁:

     arch -x86_64 pyenv install --patch 3.6.15 <<(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
  8. Switch shell to new Python version:将 shell 切换到新的 Python 版本:

     pyenv shell 3.6.15
  9. Check the currently used Python version:查看当前使用的 Python 版本:

     pyenv which python3

According to this: https://github.com/pyenv/pyenv/issues/1737#issuecomment-731672292 this is related to a commit issue and the following fixes it.据此: https://github.com/pyenv/pyenv/issues/1737#issuecomment-731672292这与提交问题有关,以下修复它。 It worked for me.它对我有用。

CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" 

LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"

pyenv install --patch 3.6.13 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

The answer by Jacob Anderson was right, but it's worth noting that there's no need to perform the dangerous step: Jacob Anderson 的回答是正确的,但值得注意的是,没有必要执行危险的步骤:

sudo rm -rf /Library/Developer/CommandLineTools 

Things worked for me (installed Python 3.6.0 on MacOS 11.4) without doing it.事情对我有用(在 MacOS 11.4 上安装了 Python 3.6.0)而没有这样做。 Thanks to Jacob!感谢雅各布!

I was facing this on mu ubuntu machine, I uninstalled Brew and reinstalled pyenv from source.我在 mu ubuntu 机器上遇到了这个问题,我卸载了 Brew 并从源代码重新安装了 pyenv。 It worked for me.它对我有用。

CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.6.13 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

it Worked on MacOs 11.2.2它适用于 MacOs 11.2.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM