Why compiling CPython 3.13.7 myself
I am compiling Python myself, because:
- For some calculation I need
scipy,numpyandmatplotlib. - I am bound to Windows here, but I can use Cygwin. I am using
matplotlibwith LaTeX, installed in Cygwin. - There is no Cygwin package for
scipy. - A self-built
scipyusesnumpy-2.x. - The
matplotlibpackage of Cygwin is built againstnumpy 1.x. - When building
matplotibmyself, the latest GCC 13 is used, but Cygwin’s Python 3.9 is GCC-11-compiled, leading to trouble withpybind11.
I’d like to have a fully functional, recent Python stack in Cygwin.
So I decided to build my whole Python environment myself, with full control in all details.
Dependencies
| Software | Package(s) |
|---|---|
| gdb | gdb 14.2-1 |
| lzma | lzma-devel, liblzma5 5.8.1-1 |
| glibc | not supported for Cygwin |
| libstdc++ | libstdc++6 13.4.0-1 |
| openssl | openssl, libssl3, libssl-devel 3.0.17-1 |
| readline | libreadline8, libreadline-devel 8.3-1 |
| zlib | zlib, zlib-devel 1.3.1-1 |
| libzstd | libzstd1, libzstd-devel 1.5.7-1 |
| libffi | libffi8, libffi-devel 3.4.7-1 |
| bzip2 | bzip2, libbz2-devel 1.0.8-1 |
| xz | xz 5.8.1-1 (no -devel package) |
| sqlite | libsqlite3_0, sqlite3, libsqlite3-devel 3.49.1-1 |
| libuuid | libuuid1, libuuid-devel 2.40.2-2 |
| gdbm | libgdbm6, gdbm, libgdbm-devel 1.24-1 |
| perf | Bound to the Linux kernel |
| expat | libexpat1, libexpat-devel, expat 2.6.4-1 |
| mpdecimal | mpdecimal-4.0.1 home brewn |
| Tcl/Tk | tcl, tcl-devel, tcl-tk, tcl-tk-devel 8.6.12-1 |
| X11 | libX11-devel 1.8.10-1; libXext-devel 1.3.6-1; libXft-devel 2.3.7-1; libXrender-devel 0.9.12-1 |
| Sockets | libgcrypt-devel 1.11.2-1; libnsl-devel, libnsl2 1.2.0-1 |
/usr/local/
I compiled libmpdec myself and installed it to /usr/local, so I’ve set
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
such that pkg-config can find it.
Compiling CPython 3.13.7
After installing the abovementioned libraries, only two errors remain in the make step:
[ERROR] _asyncio failed to import: No module named '_socket'
[ERROR] _elementtree failed to import: No module named 'pyexpat'
Following modules built successfully but were removed because they could not be imported:
_asyncio _elementtree
_socket
The _socket module exists and looks healthy. It remains to me as a pure miracle why it cannot be imported. cygcheck as well as ldd provide output looking sensible, as follows:
$ cygcheck Modules/_socket.cpython-313.dll
N:\Vollzugriff\Builds\2025\CPython\Python-3.13.7\Modules\_socket.cpython-313.dll
N:\Vollzugriff\Builds\2025\CPython\Python-3.13.7\libpython3.13.dll
N:\Vollzugriff\Programme\Cygwin\bin\cygwin1.dll
C:\WINDOWS\system32\KERNEL32.dll
C:\WINDOWS\system32\ntdll.dll
C:\WINDOWS\system32\KERNELBASE.dll
N:\Vollzugriff\Programme\Cygwin\bin\cygintl-8.dll
N:\Vollzugriff\Programme\Cygwin\bin\cygiconv-2.dll
N:\Vollzugriff\Programme\Cygwin\bin\cyggcc_s-seh-1.dll
$ ldd Modules/_socket.cpython-313.dll
ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffe9bf50000)
KERNEL32.DLL => /cygdrive/c/WINDOWS/System32/KERNEL32.DLL (0x7ffe9b700000)
KERNELBASE.dll => /cygdrive/c/WINDOWS/System32/KERNELBASE.dll (0x7ffe998b0000)
msvcrt.dll => /cygdrive/c/WINDOWS/System32/msvcrt.dll (0x7ffe9a8e0000)
libpython3.13.dll => /home/Friedrich/N/Builds/2025/CPython/Python-3.13.7/libpython3.13.dll (0x4426d0000)
cygwin1.dll => /usr/bin/cygwin1.dll (0x7ffe352c0000)
cygintl-8.dll => /usr/bin/cygintl-8.dll (0x5ee2d0000)
cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x50caa0000)
cygiconv-2.dll => /usr/bin/cygiconv-2.dll (0x3ff670000)
advapi32.dll => /cygdrive/c/WINDOWS/System32/advapi32.dll (0x7ffe9ba70000)
sechost.dll => /cygdrive/c/WINDOWS/System32/sechost.dll (0x7ffe9b230000)
RPCRT4.dll => /cygdrive/c/WINDOWS/System32/RPCRT4.dll (0x7ffe9bdf0000)
bcrypt.dll => /cygdrive/c/WINDOWS/System32/bcrypt.dll (0x7ffe99ea0000)
CRYPTBASE.DLL => /cygdrive/c/WINDOWS/SYSTEM32/CRYPTBASE.DLL (0x7ffe98f90000)
bcryptPrimitives.dll => /cygdrive/c/WINDOWS/System32/bcryptPrimitives.dll (0x7ffe99cb0000)
pyexpat
I consider the following ./configure snippet as relevant:
configure:14403: checking for --with-system-expat
configure:14415: result: no
As like for _socket, the module exists and looks good; the $ cygcheck and $ ldd calls look very similar to the ones provided for _socket.
It looks to me like if the expat library wasn’t found. It lives in /usr/lib/, and pkg-config knows it. I’ve been told that Python uses some “predefined” expat in case that it isn’t found as an external library. This would explain that the pyexpat module was built, even when the external library wasn’t found.
Summary
The Python dependencies look good. The make call for CPython 3.13.7 almost succeeds, with only _socket and pyexpat leading to problems. These are Python extension modules, are succesfully built and “look healthy”.
It is beyond my capacity to understand what is going wrong here. So any pointer would be greatly appreciated.