Can't import math in codespace

In a fresh codespace of GitHub - python/cpython: The Python programming language I did this:

./configure --enable-optimizations
make -s -j
./python -c "import math"

Result:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import math
ModuleNotFoundError: No module named 'math'

Others work fine, for example:

./python -c "import itertools; print(*itertools.chain('abc'))"

The problem seems to come from the --enable-optimizations. Without that, it works fine, as tested with this:

./python -c "import math; print(math.e)"

What’s the problem?

Full outputs:

./configure --enable-optimizations &> confy.txt
confy.txt
checking for git... found
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for Python interpreter freezing... ./_bootstrap_python
checking for python3.13... no
checking for python3.13... no
checking for python3.12... no
checking for python3.11... python3.11
checking Python for regen version... Python 3.11.6
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking MACHDEP... "linux"
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether clang accepts -g... yes
checking for clang option to enable C11 features... none needed
checking how to run the C preprocessor... clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for a sed that does not truncate output... /usr/bin/sed
checking for egrep... /usr/bin/grep -E
checking for CC compiler name... clang
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for wchar.h... yes
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
checking for GCC compatible compiler... yes
checking for clang++... no
configure:

  By default, distutils will build C++ extension modules with "clang++".
  If this is not intended, then set CXX on the configure command line.
  
checking for the platform triplet based on compiler characteristics... x86_64-linux-gnu
checking for multiarch... x86_64-linux-gnu
checking for PEP 11 support tier... x86_64-pc-linux-gnu/clang has tier 2 (supported)
checking for -Wl,--no-as-needed... yes
checking for the Android API level... not Android
checking for --with-emscripten-target... 
checking for --enable-wasm-dynamic-linking... missing
checking for --enable-wasm-pthreads... missing
checking for --with-suffix... 
checking for case-insensitive build directory... no
checking LIBRARY... libpython$(VERSION)$(ABIFLAGS).a
checking LINKCC... $(PURIFY) $(CC)
checking EXPORTSYMS... 
checking for GNU ld... yes
checking for --enable-shared... no
checking for --with-static-libpython... yes
checking for --enable-profiling... no
checking LDLIBRARY... libpython$(VERSION)$(ABIFLAGS).a
checking HOSTRUNNER... 
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for --disable-gil... no
checking for --with-pydebug... no
checking for --with-trace-refs... no
checking for --enable-pystats... no
checking for --with-assertions... no
checking for --enable-experimental-jit... no
checking for --enable-optimizations... yes
checking PROFILE_TASK... -m test --pgo --timeout=$(TESTTIMEOUT)
checking for --with-lto... no
checking for llvm-profdata... /usr/bin/llvm-profdata
checking for --enable-bolt... no
checking BOLT_INSTRUMENT_FLAGS... 
checking BOLT_APPLY_FLAGS...  -update-debug-sections -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions -icf=1 -inline-all -split-eh -reorder-functions-use-hot-size -peepholes=none -jump-tables=aggressive -inline-ap -indirect-call-promotion=all -dyno-stats -use-gnu-stack -frame-opt=hot 
checking if clang supports -fstrict-overflow and -fno-strict-overflow... yes
checking for --with-strict-overflow... no
checking if clang supports -Og optimization level... yes
checking if we can add -Wextra... yes
checking whether clang -fno-strict-aliasing accepts and needs -fno-strict-aliasing... no
checking if we can disable clang unused-parameter warning... yes
checking if we can disable clang int-conversion warning... yes
checking if we can disable clang missing-field-initializers warning... yes
checking if we can enable clang sign-compare warning... yes
checking if we can enable clang unreachable-code warning... yes
checking if we can enable clang strict-prototypes warning... yes
checking if we can make implicit function declaration an error in clang -Werror=implicit-function-declaration... yes
checking if we can use visibility in clang -fvisibility=hidden... yes
checking whether pthreads are available without options... yes
checking whether clang++ also accepts flags for thread support... no
checking for alloca.h... yes
checking for asm/types.h... yes
checking for bluetooth.h... no
checking for conio.h... no
checking for direct.h... no
checking for dlfcn.h... yes
checking for endian.h... yes
checking for errno.h... yes
checking for fcntl.h... yes
checking for grp.h... yes
checking for io.h... no
checking for langinfo.h... yes
checking for libintl.h... yes
checking for libutil.h... no
checking for linux/auxvec.h... yes
checking for sys/auxv.h... yes
checking for linux/fs.h... yes
checking for linux/limits.h... yes
checking for linux/memfd.h... yes
checking for linux/random.h... yes
checking for linux/soundcard.h... yes
checking for linux/tipc.h... yes
checking for linux/wait.h... yes
checking for netdb.h... yes
checking for net/ethernet.h... yes
checking for netinet/in.h... yes
checking for netpacket/packet.h... yes
checking for poll.h... yes
checking for process.h... no
checking for pthread.h... yes
checking for pty.h... yes
checking for sched.h... yes
checking for setjmp.h... yes
checking for shadow.h... yes
checking for signal.h... yes
checking for spawn.h... yes
checking for stropts.h... no
checking for sys/audioio.h... no
checking for sys/bsdtty.h... no
checking for sys/devpoll.h... no
checking for sys/endian.h... no
checking for sys/epoll.h... yes
checking for sys/event.h... no
checking for sys/eventfd.h... yes
checking for sys/file.h... yes
checking for sys/ioctl.h... yes
checking for sys/kern_control.h... no
checking for sys/loadavg.h... no
checking for sys/lock.h... no
checking for sys/memfd.h... no
checking for sys/mkdev.h... no
checking for sys/mman.h... yes
checking for sys/modem.h... no
checking for sys/param.h... yes
checking for sys/poll.h... yes
checking for sys/random.h... yes
checking for sys/resource.h... yes
checking for sys/select.h... yes
checking for sys/sendfile.h... yes
checking for sys/socket.h... yes
checking for sys/soundcard.h... yes
checking for sys/stat.h... (cached) yes
checking for sys/statvfs.h... yes
checking for sys/sys_domain.h... no
checking for sys/syscall.h... yes
checking for sys/sysmacros.h... yes
checking for sys/termio.h... no
checking for sys/time.h... yes
checking for sys/times.h... yes
checking for sys/timerfd.h... yes
checking for sys/types.h... (cached) yes
checking for sys/uio.h... yes
checking for sys/un.h... yes
checking for sys/utsname.h... yes
checking for sys/wait.h... yes
checking for sys/xattr.h... yes
checking for sysexits.h... yes
checking for syslog.h... yes
checking for termios.h... yes
checking for util.h... no
checking for utime.h... yes
checking for utmp.h... yes
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for sys/mkdev.h... (cached) no
checking for sys/sysmacros.h... (cached) yes
checking for bluetooth/bluetooth.h... yes
checking for net/if.h... yes
checking for linux/netlink.h... yes
checking for netlink/netlink.h... no
checking for linux/qrtr.h... yes
checking for linux/vm_sockets.h... yes
checking for linux/can.h... yes
checking for linux/can/bcm.h... yes
checking for linux/can/j1939.h... yes
checking for linux/can/raw.h... yes
checking for netcan/can.h... no
checking for clock_t... yes
checking for makedev... yes
checking for le64toh... yes
checking for mode_t... yes
checking for off_t... yes
checking for pid_t... yes
checking for size_t... yes
checking for uid_t in sys/types.h... yes
checking for ssize_t... yes
checking for __uint128_t... yes
checking size of int... 4
checking size of long... 8
checking alignment of long... 8
checking size of long long... 8
checking size of void *... 8
checking size of short... 2
checking size of float... 4
checking size of double... 8
checking size of fpos_t... 16
checking size of size_t... 8
checking alignment of size_t... 8
checking size of pid_t... 4
checking size of uintptr_t... 8
checking alignment of max_align_t... 16
checking for long double... yes
checking size of long double... 16
checking size of _Bool... 1
checking size of off_t... 8
checking whether to enable large file support... no
checking size of time_t... 8
checking for pthread_t... yes
checking size of pthread_t... 8
checking size of pthread_key_t... 4
checking whether pthread_key_t is compatible with int... yes
checking for --enable-framework... no
checking for --with-dsymutil... no
checking for dyld... no
checking for --with-address-sanitizer... no
checking for --with-memory-sanitizer... no
checking for --with-undefined-behavior-sanitizer... no
checking for --with-thread-sanitizer... no
checking the extension of shared libraries... .so
checking LDSHARED... $(CC) -shared
checking BLDSHARED flags... $(CC) -shared
checking CCSHARED... -fPIC
checking LINKFORSHARED... -Xlinker -export-dynamic
checking CFLAGSFORSHARED... 
checking SHLIBS... $(LIBS)
checking perf trampoline... yes
checking for sendfile in -lsendfile... no
checking for dlopen in -ldl... yes
checking for shl_load in -ldld... no
checking for uuid.h... no
checking for uuid >= 2.20... yes
checking for library containing sem_init... none required
checking for textdomain in -lintl... no
checking aligned memory access is required... no
checking for --with-hash-algorithm... default
checking for --with-tzpath... "/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
checking for t_open in -lnsl... no
checking for socket in -lsocket... no
checking for --with-libs... no
checking for --with-system-expat... no
checking for libffi... yes
checking for ffi_prep_cif_var... yes
checking for ffi_prep_closure_loc... yes
checking for ffi_closure_alloc... yes
checking for --with-system-libmpdec... no
checking for --with-decimal-contextvar... yes
checking for decimal libmpdec machine... uint128
checking for sqlite3 >= 3.15.2... yes
checking for sqlite3.h... yes
checking for sqlite3_bind_double in -lsqlite3... yes
checking for sqlite3_column_decltype in -lsqlite3... yes
checking for sqlite3_column_double in -lsqlite3... yes
checking for sqlite3_complete in -lsqlite3... yes
checking for sqlite3_progress_handler in -lsqlite3... yes
checking for sqlite3_result_double in -lsqlite3... yes
checking for sqlite3_set_authorizer in -lsqlite3... yes
checking for sqlite3_trace_v2 in -lsqlite3... yes
checking for sqlite3_value_double in -lsqlite3... yes
checking for sqlite3_load_extension in -lsqlite3... yes
checking for sqlite3_serialize in -lsqlite3... yes
checking for --enable-loadable-sqlite-extensions... no
checking for tcl >= 8.5.12 tk >= 8.5.12... yes
checking for gdbm.h... yes
checking for gdbm_open in -lgdbm... yes
checking for ndbm.h... yes
checking for library containing dbm_open... -lgdbm_compat
checking for ndbm presence and linker args... yes (-lgdbm_compat)
checking for gdbm/ndbm.h... yes
checking for gdbm-ndbm.h... no
checking for library containing dbm_open... -lgdbm_compat
checking for db.h... no
checking for --with-dbmliborder... gdbm:ndbm:bdb
checking for _dbm module CFLAGS and LIBS... -DUSE_GDBM_COMPAT -lgdbm_compat
checking if PTHREAD_SCOPE_SYSTEM is supported... yes
checking for pthread_sigmask... yes
checking for pthread_getcpuclockid... yes
checking if --enable-ipv6 is specified... yes
checking if RFC2553 API is available... yes
checking for IPV6_INRIA_VERSION defined in netinet/in.h... no
checking for __KAME__ defined in netinet/in.h... no
checking for __GLIBC__ defined in features.h... yes
checking ipv6 stack type... linux-glibc
checking CAN_RAW_FD_FRAMES... yes
checking for CAN_RAW_JOIN_FILTERS... yes
checking for --with-doc-strings... yes
checking for stdatomic.h... yes
checking for builtin __atomic_load_n and __atomic_store_n functions... yes
checking for --with-mimalloc... yes
checking for --with-pymalloc... yes
checking for --with-freelists... yes
checking for --with-c-locale-coercion... yes
checking for --with-valgrind... no
checking for --with-dtrace... no
checking for dlopen... yes
checking DYNLOADFILE... dynload_shlib.o
checking MACHDEP_OBJS... none
checking for accept4... yes
checking for alarm... yes
checking for bind_textdomain_codeset... yes
checking for chmod... yes
checking for chown... yes
checking for clock... yes
checking for closefrom... yes
checking for close_range... yes
checking for confstr... yes
checking for copy_file_range... yes
checking for ctermid... yes
checking for dup... yes
checking for dup3... yes
checking for execv... yes
checking for explicit_bzero... yes
checking for explicit_memset... no
checking for faccessat... yes
checking for fchmod... yes
checking for fchmodat... yes
checking for fchown... yes
checking for fchownat... yes
checking for fdopendir... yes
checking for fdwalk... no
checking for fexecve... yes
checking for fork... yes
checking for fork1... no
checking for fpathconf... yes
checking for fstatat... yes
checking for ftime... yes
checking for ftruncate... yes
checking for futimens... yes
checking for futimes... yes
checking for futimesat... yes
checking for gai_strerror... yes
checking for getegid... yes
checking for geteuid... yes
checking for getgid... yes
checking for getgrent... yes
checking for getgrgid... yes
checking for getgrgid_r... yes
checking for getgrnam_r... yes
checking for getgrouplist... yes
checking for gethostname... yes
checking for getitimer... yes
checking for getloadavg... yes
checking for getlogin... yes
checking for getpeername... yes
checking for getpgid... yes
checking for getpid... yes
checking for getppid... yes
checking for getpriority... yes
checking for _getpty... no
checking for getpwent... yes
checking for getpwnam_r... yes
checking for getpwuid... yes
checking for getpwuid_r... yes
checking for getresgid... yes
checking for getresuid... yes
checking for getrusage... yes
checking for getsid... yes
checking for getspent... yes
checking for getspnam... yes
checking for getuid... yes
checking for getwd... yes
checking for grantpt... yes
checking for if_nameindex... yes
checking for initgroups... yes
checking for kill... yes
checking for killpg... yes
checking for lchown... yes
checking for linkat... yes
checking for lockf... yes
checking for lstat... yes
checking for lutimes... yes
checking for madvise... yes
checking for mbrtowc... yes
checking for memrchr... yes
checking for mkdirat... yes
checking for mkfifo... yes
checking for mkfifoat... yes
checking for mknod... yes
checking for mknodat... yes
checking for mktime... yes
checking for mmap... yes
checking for mremap... yes
checking for nice... yes
checking for openat... yes
checking for opendir... yes
checking for pathconf... yes
checking for pause... yes
checking for pipe... yes
checking for pipe2... yes
checking for plock... no
checking for poll... yes
checking for posix_fadvise... yes
checking for posix_fallocate... yes
checking for posix_openpt... yes
checking for posix_spawn... yes
checking for posix_spawnp... yes
checking for posix_spawn_file_actions_addclosefrom_np... yes
checking for pread... yes
checking for preadv... yes
checking for preadv2... yes
checking for process_vm_readv... yes
checking for pthread_cond_timedwait_relative_np... no
checking for pthread_condattr_setclock... yes
checking for pthread_init... no
checking for pthread_kill... yes
checking for ptsname... yes
checking for ptsname_r... yes
checking for pwrite... yes
checking for pwritev... yes
checking for pwritev2... yes
checking for readlink... yes
checking for readlinkat... yes
checking for readv... yes
checking for realpath... yes
checking for renameat... yes
checking for rtpSpawn... no
checking for sched_get_priority_max... yes
checking for sched_rr_get_interval... yes
checking for sched_setaffinity... yes
checking for sched_setparam... yes
checking for sched_setscheduler... yes
checking for sem_clockwait... yes
checking for sem_getvalue... yes
checking for sem_open... yes
checking for sem_timedwait... yes
checking for sem_unlink... yes
checking for sendfile... yes
checking for setegid... yes
checking for seteuid... yes
checking for setgid... yes
checking for sethostname... yes
checking for setitimer... yes
checking for setlocale... yes
checking for setpgid... yes
checking for setpgrp... yes
checking for setpriority... yes
checking for setregid... yes
checking for setresgid... yes
checking for setresuid... yes
checking for setreuid... yes
checking for setsid... yes
checking for setuid... yes
checking for setvbuf... yes
checking for shutdown... yes
checking for sigaction... yes
checking for sigaltstack... yes
checking for sigfillset... yes
checking for siginterrupt... yes
checking for sigpending... yes
checking for sigrelse... yes
checking for sigtimedwait... yes
checking for sigwait... yes
checking for sigwaitinfo... yes
checking for snprintf... yes
checking for splice... yes
checking for strftime... yes
checking for strlcpy... no
checking for strsignal... yes
checking for symlinkat... yes
checking for sync... yes
checking for sysconf... yes
checking for tcgetpgrp... yes
checking for tcsetpgrp... yes
checking for tempnam... yes
checking for timegm... yes
checking for times... yes
checking for tmpfile... yes
checking for tmpnam... yes
checking for tmpnam_r... yes
checking for truncate... yes
checking for ttyname... yes
checking for umask... yes
checking for uname... yes
checking for unlinkat... yes
checking for unlockpt... yes
checking for utimensat... yes
checking for utimes... yes
checking for vfork... yes
checking for wait... yes
checking for wait3... yes
checking for wait4... yes
checking for waitid... yes
checking for waitpid... yes
checking for wcscoll... yes
checking for wcsftime... yes
checking for wcsxfrm... yes
checking for wmemcmp... yes
checking for writev... yes
checking for getentropy... yes
checking for getgroups... yes
checking for system... yes
checking for clang options needed to detect all undeclared functions... -fno-builtin
checking whether dirfd is declared... yes
checking for chroot... yes
checking for link... yes
checking for symlink... yes
checking for fchdir... yes
checking for fsync... yes
checking for fdatasync... yes
checking for epoll_create... yes
checking for epoll_create1... yes
checking for kqueue... no
checking for prlimit... yes
checking for _dyld_shared_cache_contains_path... no
checking for memfd_create... yes
checking for eventfd... yes
checking for timerfd_create... yes
checking for ctermid_r... no
checking for flock declaration... yes
checking for flock... yes
checking for getpagesize... yes
checking for broken unsetenv... no
checking for true... true
checking for inet_aton in -lc... yes
checking for chflags... no
checking for lchflags... no
checking for zlib >= 1.2.0... yes
checking for bzip2... yes
checking for liblzma... yes
checking for hstrerror... yes
checking for getservbyname... yes
checking for getservbyport... yes
checking for gethostbyname... yes
checking for gethostbyaddr... yes
checking for getprotobyname... yes
checking for inet_aton... yes
checking for inet_ntoa... yes
checking for inet_pton... yes
checking for getpeername... (cached) yes
checking for getsockname... yes
checking for accept... yes
checking for bind... yes
checking for connect... yes
checking for listen... yes
checking for recvfrom... yes
checking for sendto... yes
checking for setsockopt... yes
checking for socket... yes
checking for setgroups... yes
checking for openpty... yes
checking for library containing login_tty... no
make -s -j &> maky.txt
maky.txt
Running code to generate profile data (this can take a while):
Building with support for profile generation:
In file included from Python/optimizer_analysis.c:408:
Python/optimizer_cases.c.h:52:32: warning: code will never be executed [-Wunreachable-code]
            stack_pointer[0] = value;
                               ^~~~~
/usr/bin/ld: cannot find /usr/lib64/clang/15.0.7/lib/linux/libclang_rt.profile-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:3267: Modules/_contextvars.cpython-313-x86_64-linux-gnu.so] Error 1
make[2]: *** Waiting for unfinished jobs....
/usr/bin/ld: cannot find /usr/lib64/clang/15.0.7/lib/linux/libclang_rt.profile-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:3300: Modules/_statistics.cpython-313-x86_64-linux-gnu.so] Error 1
Objects/typeobject.c:120:1: warning: unused function 'static_builtin_index_is_set' [-Wunused-function]
static_builtin_index_is_set(PyTypeObject *self)
^
/usr/bin/ld: cannot find /usr/lib64/clang/15.0.7/lib/linux/libclang_rt.profile-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:3402: Modules/_uuid.cpython-313-x86_64-linux-gnu.so] Error 1
/usr/bin/ld: cannot find /usr/lib64/clang/15.0.7/lib/linux/libclang_rt.profile-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:3373: Modules/_posixshmem.cpython-313-x86_64-linux-gnu.so] Error 1
Python/pystate.c:1122:1: warning: unused function 'check_interpreter_whence' [-Wunused-function]
check_interpreter_whence(long whence)
^
1 warning generated.
1 warning generated.
1 warning generated.
make[1]: *** [Makefile:871: profile-gen-stamp] Error 2
make: *** [Makefile:883: profile-run-stamp] Error 2
./python -c "import math" &> mathy.txt
mathy.txt
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import math
ModuleNotFoundError: No module named 'math'

Given that make failed, it’s expect that whatever artifacts you get out won’t work correctly.

Looking at the first build error:

It appears you’re missing some development dependencies for your compiler (clang). You’ll need to fix that, either by installing the right system package for whatever platform you’re on (e.g. libclang-common-15-dev for apt) or by following the clang setup steps in the dev guide.

1 Like

Thanks. I might try that. I was hoping such things were already taken care of. Am I creating the codespace incorrectly? I just tapped the “+” here:

@brettcannon Seems you’re the one doing the codespace. Is it simply not intended/prepared to do builds with optimizations enabled? Or did I do something wrong there? I think I did what the devguide instructions say, except I don’t see that “green Create codespace on main button”. I just tried again, and the fresh codespace does already have CPython built (I mean I can execute ./python, and it says it was built 2.5 hours earlier), so it seems I did successfully use your devcontainer?

It’s only there if you don’t have a codespace already running.

It’s not, because it’s intended for development which generally doesn’t require building with PGO. You can add what’s needed by running dnf install compiler-rt.

2 Likes

Hmm, well, as the Optimization section says, “If you are trying to improve CPython’s performance, you will probably want to use an optimized build of CPython.” Doesn’t seem unusual.

Thanks, that seems to have done the trick (and wasn’t as intimidating as the lengthy procedure in the clang setup description).

Sadly it’s now slower than earlier today without the optimizations, like 40 ns instead of 28 ns in one benchmark. Maybe I got a slower machine this time. I’ll play around with it some more.