Cannot install Python from source on Apple Silicon M1

I am trying to install Python from source according to the readme using:

./configure
make <-- Error happens here
make test
sudo make altinstall

However, I cannot complete the make command since it fails with:

Undefined symbols for architecture arm64:
  "_libintl_bindtextdomain", referenced from:
      __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_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

I stumbled across this bug report: Issue 46975: clang: error: linker command failed with exit code 1 (use -v to see invocation) on m1 mac - Python tracker

I have indeed brew x86_64 (and arm64) installed and it seems that this somehow interferes. In detail it looks like the gettext package is causing the problem. I don’t really get how this was solved in the cython bug report. I cannot uninstall the package since it is a dependency of some other packages. Somehow I need to tell make not to use the shared libs from brew. Any ideas how to do that?

I would check where configure looks for headers and libs.
Look for options to override configure looking in the wrong place.
Have you built you own libintl for use in python build?

I have to admit I am not that profound with make. I guess I would not be able to find options that look in the wrong place. And I have not build my own libintl for building Python. Any suggestion where I should start looking?

You are likely to need to build a lots if dependencies to get the full features of python working.
If you are new to building from source this may take a while.

Why do you need to build python from source?
Why not install the python.org version?

You’re right. I am now with the installer from python.org. I wanted to install multiple Python versions and thought this was not possible using the installer. I’ve been using conda for years, but for a specific project I need to move away from that. So it’s been a while since I used Python outside of conda. I stumbled across some information that make altinstall would be an option to create independent installs of multiple versions and I didn’t now I can just install them in parallel (even though I am now pinned to the versions, where installers exist). maybe I’ll look into building (in general) at a later time point, but currently I have enough other things besides that on my plate :). Thanks for your help till here.

You can install python.org versions side by side without problem.
Beware of that each install with edit you shell profile, check that you lime what it did.

Also there is a symlink in /usr/local/bin/python3 that you might what to set to your default version. It will be set to the version of python you last installed otherwise.

1 Like