Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing python 3.6 with pyenv on Mac OS Big Sur

Tags:

python

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:

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. I currently have python 3.8, but need 3.6 in order to run:

conda install -c deezer-research spleeter 
like image 954
Jacob Anderson Avatar asked Mar 04 '21 20:03

Jacob Anderson


People also ask

Do I need to install python before Pyenv?

pyenv is a wonderful tool for managing multiple Python versions. Even if you already have Python installed on your system, it is worth having pyenv installed so that you can easily try out new language features or help contribute to a project that is on a different version of Python.

What version of python comes with macOS Big Sur?

Show activity on this post. No, on Apple Macs being shipped with Big Sur, Python 2 and Python 3 are both still included.

What is the best way to install python on Mac?

Install Python 3 with the Official Installer First, download an installer package from the Python website. To do that, visit https://www.python.org/downloads/ on your Mac; it detects your operating system automatically and shows a big button for downloading the latest version of Python installer on your Mac.


2 Answers

Thanks to jordanm, The solution was to follow 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; 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:

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)

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)
like image 96
Jacob Anderson Avatar answered Oct 18 '22 20:10

Jacob Anderson


According to this: https://github.com/pyenv/pyenv/issues/1737#issuecomment-731672292 this is related to a commit issue and the following fixes it. 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)

like image 23
maede rayati Avatar answered Oct 18 '22 21:10

maede rayati