37

I am trying to install multiple versions of Python on my laptop running MacOS Big Sur v11.1. I initially installed xcode command line tools, homebrew, and python via instructions here

xcode-select --install

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

brew install python

But later on involuntarily upgraded python to 3.9, and I need to go back to 3.7.9. So I installed pyenv and attempted to install python 3.7.9 per instructions here

brew install pyenv

pyenv install 3.7.9

But I encountered the following error:

/var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108 /usr/local/Cellar
/var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108/Python-3.7.9 /var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108 /usr/local/Cellar
checking build system type... x86_64-apple-darwin20.2.0
checking host system type... x86_64-apple-darwin20.2.0
checking for python3.7... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/8n/ml0qwc091w9bhpszzxy9djl00000gn/T/python-build.20210118111111.56108/Python-3.7.9':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

From other answers online it seems my gcc may be out of date. I checked my gcc version with

[/usr/local/Cellar]$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
    --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.3 (clang-1103.0.32.62) Target: x86_64-apple-darwin20.2.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Which seems to indicate I am on version 4.2.1. I have not been able to find a way to update it on my own yet, but did brew install gcc which did not resolve the problem. Any help would be much appreciated

EDIT: Seems pyenv is using clang and not gcc. Perhaps xcode-select installed both? clang --version returns:

Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
jesse fredrickson
  • 371
  • 1
  • 3
  • 4
  • "involuntarily upgraded python to 3.9, and I need to go back to 3.7.9" - doesn't `brew` provide any functionality to install the exact version you need? See e.g. https://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula – ForceBru Jan 18 '21 at 17:02
  • Yes, I can `brew install python@3.7` (and I have). However I have not been able to `brew switch python 3.7`, and `brew info python` only shows @3.9 installed for some reason. `ll /usr/local/Cellar | grep python` shows python@3.9 and python@3.7 – jesse fredrickson Jan 18 '21 at 19:46
  • 2
    I'm also wary that going this route - using homebrew to manage multiple python installations - might be trickier than using pyenv. – jesse fredrickson Jan 18 '21 at 19:49

7 Answers7

48

This worked for me: I removed the command line tools as root and reinstalled ...

Your Command Line Tools (CLT) does not support macOS 11. It is either outdated or was modified. Please update your Command Line Tools (CLT) or delete it if no updates are available.

Update them from Software Update in System Preferences or run:

softwareupdate --all --install --force

If that doesn't show you any updates, run:

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

Alternatively, manually download them from:

https://developer.apple.com/download/more/.

David Buck
  • 3,752
  • 35
  • 31
  • 35
carter
  • 583
  • 3
  • 5
10

Seems there is a problem with Xcode, zlib and compiler options. From brew they made some patches to 3.8.0 python version.

My configuration

$ sw_vers
ProductName:    macOS
ProductVersion: 11.2.3
BuildVersion:   20D91
$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

This worked for me to install 3.8.3 and 3.9.0


# Re-install Xcode
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

# Install zlib and bzip2 using brew
brew reinstall zlib bzip2
 
# Install tcl-tk tkinter
brew install tcl-tk

# Uninstall previous versions from python
pyenv uninstall 3.8.3
pyenv uninstall 3.9.0

# Install python 3.8.3 patched
env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include -L$(brew --prefix zlib)/include -L$(brew --prefix bzip2)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include -I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
  LDFLAGS="-I$(brew --prefix tcl-tk)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"
  pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
  
env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include -L$(brew --prefix zlib)/include -L$(brew --prefix bzip2)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include -I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
  LDFLAGS="-I$(brew --prefix tcl-tk)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"
  pyenv install 3.9.0

My sources where I did come up with the solution:

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
nenetto
  • 354
  • 2
  • 6
10

I used the following and it worked

CC=gcc pyenv install 3.7.10

Max Bregman
  • 101
  • 1
  • 2
  • 1
    Thx, this worked for me as well (while re-installing xcode didn't help). Would be nice to know why this works.. – mona-mk Sep 29 '22 at 11:36
1

For me it was a problem with the clang compiler that pyenv was trying to use. As I had an active Anaconda version that was set up with pyenv, it tried to use the clang version bundled with Anaconda:

$ clang --version
clang version 10.0.0
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Users/myuser/.pyenv/versions/anaconda3-2020.02/bin

With:

pyenv shell system

I was able to use the XCode clang compiler and everything worked all right. I was able to install the new version of Python with a typical:

pyenv install 3.9.5
nudomarinero
  • 106
  • 3
1

It got fixed with yesterdays release. attaching the git closed issue here

in a nutshell pyenv python versions of 3.7.13, 3.8.13, 3.9.11 and 3.10.3 will work fine from now on.

A Avinash
  • 11
  • 1
0

I know this is a little old but I just ran into the issue and removing and reinstalling command line tools worked for me.

Dale
  • 61
  • 1
  • 6
0

Reinstall Xcode, also worked for me!

nullck➜~» sw_vers                                                                                                                                                                                                                  [11:03:20]
ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95
nullck➜~» sudo rm -rf /Library/Developer/CommandLineTools                                                                                                                                                                          [11:03:53]
Password:
sudo: a password is required
nullck➜~» sudo rm -rf /Library/Developer/CommandLineTools                                                                                                                                                                          [11:04:37]
Password:
nullck➜~» xcode-select --install                                                                                                                                                                                                   [11:05:07]
xcode-select: note: install requested for command line developer tools
nullck➜~»                                                                                                                                                                                                                          [11:06:31]
nullck➜~»                                                                                                                                                                                                                          [11:37:33]
nullck➜~» pyenv install 3.10.1                                                                                                                                                                                                     [11:37:34]
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.10.1.tar.xz...
-> https://www.python.org/ftp/python/3.10.1/Python-3.10.1.tar.xz
Installing Python-3.10.1...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.10.1 to /Users/nullck/.pyenv/versions/3.10.1
nullck
  • 37
  • 2