coiai Logo

This article is an English translation of the original Japanese post. Read the Japanese original →

Fixing a pyenv Install Error

April 1, 2024

Categories: 未分類

Environment

MacBook Air M1, 2020
MacOS 14.4.1

The problem

I installed pyenv via Homebrew.
I confirmed the install with pyenv –version, but

pyenv install 3.11.1

would fail partway through with an error whenever I ran it.
Here's the log from that.

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

Inspect or clean up the working tree at /var/folders/v6/jcq_s0rd58x3kph7trv7jfjw0000gn/T/python-build.20240401212257.5503
Results logged to /var/folders/v6/jcq_s0rd58x3kph7trv7jfjw0000gn/T/python-build.20240401212257.5503.log

Last 10 log lines:
      __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....
2 warnings generated.

How I fixed it

I solved it using the approach in this issue.

Uninstalling openssl, gettext, and readline

The –ignore-dependencies option lets you uninstall a package while ignoring its dependencies.

brew uninstall --ignore-dependencies openssl gettext readline

Reinstalling openssl, gettext, and readline

The -x86_64 option is used to reinstall a package for a specific architecture. This lets you make sure it's reinstalled for the right architecture.

 /usr/bin/arch -x86_64 brew install openssl gettext readline

Installing pyenv.

Here too, I added the -x86_64 option.

$ /usr/bin/arch -x86_64 pyenv install 3.11.2

And this time it succeeded.

However, after this, $python –version gave a "command not found" error,
while $python3 –version worked fine.
I cover that issue in the post below.

Getting $python and $python3 to the Same Version on Mac

By the way, here's what those three packages I reinstalled actually do:
openssl is a library that provides security-related functionality.

gettext is a toolset for building internationalized programs. Its main purpose is managing text messages within a program in a translatable format. It's used when localizing UI text in multilingual applications and libraries.

readline is a library that supports text input in command-line interfaces (CLIs). Its main features are editing the text a user types at the command line, managing history, and providing completion. It's used to improve interactive input in terminals and shells.

All three are widely used in programming and system administration contexts.

Other things I tried that didn't work

Reinstalling pyenv

This was the first thing I tried, and it didn't work.

$ brew uninstall pyenv
$ brew install pyenv

I double- and triple-checked that I'd written the following in .zshrc and .zprofile, but it doesn't seem related to the install-time error.

# pyenv settings
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Reinstalling the command line tools

Every blog post mentioned running the code below, but it didn't help.
I also tried combining it with a macOS update and a restart, but no luck.

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