Skip to content

Instantly share code, notes, and snippets.

@aputs
Created December 2, 2020 15:13
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aputs/1e898436c70c23ea739899a7942a720a to your computer and use it in GitHub Desktop.
Save aputs/1e898436c70c23ea739899a7942a720a to your computer and use it in GitHub Desktop.
pyenv install python versions on big sur
export MACOSX_DEPLOYMENT_TARGET=11.0
brew install pyenv bzip2 zlib xz openssl@1.1
## 3.6.8
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.8 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
## 3.6.12
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.12 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
## 3.7.9
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 3.7.9
@andrewcrook
Copy link

Thanks for this, saved me a ton of time and frustration!

Didn’t work for M1 Mac. At the moment I use the dev versions basically, looking at the projects, there have been updates to use the latest MacOS SDK and adding the architecture options I.e universal binaries for x64 and ARM64. Waiting for the next releases from the dev branches.

@ckoppelman
Copy link

After hours of searching, this works for 3.6.8. Thank you!

@pauloesteban
Copy link

Sadly not working for 3.7.3

@aputs
Copy link
Author

aputs commented Jun 24, 2021

Thanks for this, saved me a ton of time and frustration!

Didn’t work for M1 Mac. At the moment I use the dev versions basically, looking at the projects, there have been updates to use the latest MacOS SDK and adding the architecture options I.e universal binaries for x64 and ARM64. Waiting for the next releases from the dev branches.

you might want to install both brew on arm and x86_64, use arch -x86_64 bash then install brew on that shell, then add /opt/homebrew/bin and /usr/local/bin on your path. once the binaries are built on the proper platform rosetta will kick if needed.

@andrewcrook
Copy link

andrewcrook commented Jun 24, 2021

you might want to install both brew on arm and x86_64, use arch -x86_64 bash then install brew on that shell, then add /opt/homebrew/bin and /usr/local/bin on your path. once the binaries are built on the proper platform rosetta will kick if needed.

I made a copy of the terminal app and set it to use Rosetta so whole thing is 86_x64 then used arch to get the platform and using if statements in my .zshrc to change config when loaded on either platform.

Another alternative, use Docker Desktop for macOS to run amd64 Linux using its builtin QEMU emulation and run your python dev environment there.

As I said the build scripts for all previous versions of macOS python need updating or you could use the latest. I presume those dev versions have been released since.

.zshrc example

_ARCH=$(arch)
PROMPT="$_ARCH $PROMPT”

if [[ "$_ARCH" == "i386" ]]; then
  .....x86_64 paths for homebrew and config app etc...
else
  ...ARM64 paths for homebrew and config app etc .....
endif

pyenv is written in python so I didn’t need to installed twice. I just had two different .pyenv directories .pyenv and .pyenv -i386.

@andrewcrook
Copy link

It would seem that the building scripts seem to build for x86_64 or ARM64e

python3.10: Mach-O 64-bit executable arm64

With many versions of python with no build configuration for ARM64e

the macOS builtin python3 has been built as a universal binary and works with both

/usr/bin/python3: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/python3 (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python3 (for architecture arm64e): Mach-O 64-bit executable arm64e

It would be nice to have all the main versions of Python as universal binaries. 2.7 maybe for old code when porting.
However, Rosetta will most likely be phased out when Apple Silicon takes over.
So everything will be complied for arm64e
Therefore tech like remote development, VMs, and Docker will have to be used if Intel is your target platform.
of course, python should be python i.e portable, but you may find platform inderpedent unintended differences, compatability issues and bugs with certain versions of interpreters.

@andrewcrook
Copy link

Sadly not working for 3.7.3

if you can fine one that works in 3.7.x where x >= 3 it's unlucky anything will break as they’re are minor updates.

@taegyunkim
Copy link

taegyunkim commented Sep 17, 2021

Thank you, 3.6.12 command worked like a charm.

@in03
Copy link

in03 commented Apr 11, 2022

I keep getting this error installing 3.6.8 as above. Anyone have some insight?
Oddly enough it looks like it keeps going.
Running Big Sur on Mac Mini M1.

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

Inspect or clean up the working tree at /var/folders/lk/zvz8b1mj75xcs2_vz6ln9wz40000gn/T/python-build.20220411160332.92993
Results logged to /var/folders/lk/zvz8b1mj75xcs2_vz6ln9wz40000gn/T/python-build.20220411160332.92993.log

Last 10 log lines:
         install|*) ensurepip="" ;; \
      esac; \
       ./python.exe -E -m ensurepip \
         $ensurepip --root=/ ; \
   fi
Looking in links: /var/folders/lk/zvz8b1mj75xcs2_vz6ln9wz40000gn/T/tmptxti00w0
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment