ModuleNotFoundError: No module named '_sysconfigdata __darwin _darwin'

Note: I had to inject spaces into “_sysconfig__darwin_darwin” to be allowed to post this.

I am trying to build Python 3.11.4 from source on a Mac. It fails with the following error:

build	09-Aug-2023 14:58:46	b - INFO - ./python.exe -E -S -m sysconfig --generate-posix-vars ;\
build	09-Aug-2023 14:58:46	b - INFO - 	if test $? -ne 0 ; then \
build	09-Aug-2023 14:58:46	b - INFO - 		echo "generate-posix-vars failed" ; \
build	09-Aug-2023 14:58:46	b - INFO - 		rm -f ./pybuilddir.txt ; \
build	09-Aug-2023 14:58:46	b - INFO - 		exit 1 ; \
build	09-Aug-2023 14:58:46	b - INFO - 	fi
build	09-Aug-2023 14:58:47	b - INFO - Traceback (most recent call last):
build	09-Aug-2023 14:58:47	b - INFO -   File "<frozen runpy>", line 198, in _run_module_as_main
build	09-Aug-2023 14:58:47	b - INFO -   File "<frozen runpy>", line 88, in _run_code
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 851, in <module>
build	09-Aug-2023 14:58:47	b - INFO -     _main()
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 839, in _main
build	09-Aug-2023 14:58:47	b - INFO -     _generate_posix_vars()
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel//nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 469, in _generate_posix_vars
build	09-Aug-2023 14:58:47	b - INFO -     makefile = get_makefile_filename()
build	09-Aug-2023 14:58:47	b - INFO -                ^^^^^^^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 453, in get_makefile_filename
build	09-Aug-2023 14:58:47	b - INFO -     return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile')
build	09-Aug-2023 14:58:47	b - INFO -                         ^^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel//nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 626, in get_path
build	09-Aug-2023 14:58:47	b - INFO -     return get_paths(scheme, vars, expand)[name]
build	09-Aug-2023 14:58:47	b - INFO -            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 616, in get_paths
build	09-Aug-2023 14:58:47	b - INFO -     return _expand_vars(scheme, vars)
build	09-Aug-2023 14:58:47	b - INFO -            ^^^^^^^^^^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 265, in _expand_vars
build	09-Aug-2023 14:58:47	b - INFO -     _extend_dict(vars, get_config_vars())
build	09-Aug-2023 14:58:47	b - INFO -                        ^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 670, in get_config_vars
build	09-Aug-2023 14:58:47	b - INFO -     _init_posix(_CONFIG_VARS)
build	09-Aug-2023 14:58:47	b - INFO -   File "/Users/devel/nshield/python/deps/Python-3.11.4/Lib/sysconfig.py", line 531, in _init_posix
build	09-Aug-2023 14:58:47	b - INFO -     _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
build	09-Aug-2023 14:58:47	b - INFO -             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
build	09-Aug-2023 14:58:47	b - INFO - ModuleNotFoundError: No module named '_sysconfigdata__darwin_darwin'

Earlier on, I get:

build	09-Aug-2023 14:56:46	b - INFO - checking for C compiler vendor... clang
build	09-Aug-2023 14:56:46	b - INFO - 
build	09-Aug-2023 14:56:46	b - INFO - ********************************************************
build	09-Aug-2023 14:56:46	b - INFO - * WARNING: Don't know the best CFLAGS for this system  *
build	09-Aug-2023 14:56:46	b - INFO - * Use ./configure CFLAGS=... to specify your own flags *
build	09-Aug-2023 14:56:46	b - INFO - * (otherwise, a default of CFLAGS=-O3 will be used)    *
build	09-Aug-2023 14:56:46	b - INFO - ********************************************************
build	09-Aug-2023 14:56:46	b - INFO - 

Which is a bit of a worry.

The machine is on macOS Monterey.

When you run python like that does it know where to look for its stdlib?
Do you need to set PYTHONPATH?

You could try:

./python.exe
import sys
sys.path

Why is it python.exe on a macOS system?

Why is it python.exe on a macOS system?

That’s a very good question. I have no idea.

You could try:

The problem is that this occurs in the middle of building python. Specifically, after I have done Configure, I invoke make and get this error.

Probably because it’s on a case-insensitive file system. On my (Linux ext4) system, there’s python the binary and Python the source directory; if those would be indistinguishable, the executable is renamed python.exe.

Because macOS has a case sensitive file system and the source tree contains a “Python” subdirectory. Therefore the executable is created as “python.exe” in in the build tree, and renamed to the correct name during installation.

1 Like

Hello all, I ran into this again and it seems to be a makefile concurrency issue (I’m building with make -j 4) I don’t get this problem on a faster machine with more cores.

Makefile.pre (in 3.11 at least) does cat pybuilddir.txt to compute the full path to copy the sysconfigdata module to. In cases where the failure is above that file is nowhere to be seen in my build tree.

If once this happens, I just run make again, pybuilddir.txt gets created and the build completes

doing:

make -j 4 pybuilddir.txt && make -j4

Seems to work reliably

Scratch that. nope