Installing pyenv and possible troubles on Mac M1‐M4 - Voronenko/macfiles GitHub Wiki

pyenv installation problems

If your local setup is per macfiles, your pyenv installation should work out of the box with:

install-pyenv:
 brew reinstall ca-certificates
 brew install openssl readline sqlite3 xz zlib tcl-tk@8 libb2
 brew install pyenv
 echo "Installing virtualenv plugin"
 brew install pyenv-virtualenv
 echo "Usage: pyenv virtualenv 3.9.15 name-of-virtual-env"

This goes in line with official pyenv installation instructions. https://github.com/pyenv/pyenv/wiki#suggested-build-environment => https://github.com/pyenv/pyenv?tab=readme-ov-file#b-set-up-your-shell-environment-for-pyenv => https://github.com/pyenv/pyenv/wiki#suggested-build-environment

If during installation you face one of the following errors:

Security certificate problem

Ensure you've instructed pyenv to use openssl v3 instead of v1, as homebrew openssl v1 is badly broken at least on arm64 macs.

export PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA="openssl@3"

In macfiles it is already addressed

if [ -d ~/.pyenv ](/Voronenko/macfiles/wiki/--d-~/.pyenv-); then
export PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA="openssl@3"
export PYENV_ROOT="$(pyenv root)"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi

Linking errors during python version installation, including DYLD_LIBRARY_PATH errors

If python version installation fails with error messages like:

DYLD_LIBRARY_PATH=/var/folders/dm/s9twt_h92t15b27mn940zdqw0000gp/T/python-build.20250324114735.79587/Python-3.9.15 ./python.exe -E -m ensurepip \
   $ensurepip --root=/ ; \
 fi
dyld[93892]: missing symbol called

or

Undefined symbols for architecture arm64:
 "_libintl_bindtextdomain", referenced from:
   __locale_bindtextdomain in _localemodule.o
   __locale_bindtextdomain in _localemodule.o
 "_libintl_dcgettext", referenced from:
   __locale_dcgettext in _localemodule.o
 "_libintl_dgettext", referenced from:
   __locale_dgettext in _localemodule.o
 "_libintl_gettext", referenced from:
   __locale_gettext in _localemodule.o
 "_libintl_setlocale", referenced from:
   __locale_setlocale in _localemodule.o
   __locale_setlocale in _localemodule.o
   __locale_localeconv in _localemodule.o
   __locale_localeconv in _localemodule.o
   __locale_localeconv in _localemodule.o
   __locale_localeconv in _localemodule.o
 "_libintl_textdomain", referenced from:
   __locale_textdomain in _localemodule.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Programs/_freeze_module] Error 1
make: *** Waiting for unfinished jobs....

Most likely reason on macOS running on M1-M4 chips is that you have ugly mix of homebrew for arm and x86 architectures. (Don't ask me how you did it, perhaps you haven't used macfiles from the start)

And reliable way to fix that might be:

(A)

In zshrc, like macfiles does, ensure you have forced arm64 version of the homebrew in terminal sessions

eval $(/opt/homebrew/bin/brew shellenv)

(B) You might have mix of the libraries in x86 location (ls /usr/local/lib/libint*) and arm64 location (ls /opt/homebrew/lib/libint*). As you are working or arm machine, you should have all necessary libraries in arm64 location.

If, saying, you observe situation like

ls /usr/local/lib/libint*
/usr/local/lib/libintl.8.dylib /usr/local/lib/libintl.dylib
/usr/local/lib/libintl.a

ls /opt/homebrew/lib/libint*
zsh: no matches found: /opt/homebrew/lib/libint*

This is exactly scenario: libraries are installed for the wrong architecture.

Apply (A), open fresh shell. Reinstall typical python dependencies for arm64 architecture.

brew install gettext
brew link gettext --force

brew install openssl readline sqlite3 xz zlib tcl-tk@8 libb2

brew install ncurses

After that you should be able to install python versions with pyenv for arm64 architecture.