从源代码构建 Python3.7.3 缺少“_ctypes”

Ami*_*ert 8 python python-3.x

我正在尝试从源代码构建 Python-3.7.3,ensurepip但出现此错误:

ModuleNotFoundError: No module named '_ctypes'
Run Code Online (Sandbox Code Playgroud)

网上的所有答案都说这libffi-dev是需要的,但我已经安装了它,但它仍然给我这个错误。

root@4b6d672f1334:/Python-3.7.3# find / -name libffi.*
/usr/lib/pkgconfig/libffi.pc
/usr/lib/libffi.a
/usr/lib/libffi.so
/usr/lib/libffi.so.5.0.10
/usr/lib/libffi.so.5
/usr/share/info/libffi.info.gz
Run Code Online (Sandbox Code Playgroud)

构建位于来自 的容器映像中ubuntu:10.04。它是故意这么旧的,因为我正在使用 PyInstaller 来编译应用程序,并且它需要在具有旧 glibc (2.11) 的计算机上运行,​​并且此映像是我能找到的唯一具有此旧版本的映像。

我对 Python-2.7.16 做了同样的事情,它工作没有任何问题。

更新 Python-3.6.8 也可以正常工作,没有任何问题

Ami*_*ert 6

我找到了解决方案我在这里

问题可能出在旧版本的 libffi-dev 上,解决方案是从源代码构建并安装 libffi,然后构建 Python3.7.3

构建libffi:

wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar xzf libffi-3.2.1.tar.gz
cd libffi-3.2.1
./configure --disable-docs
make
make install
Run Code Online (Sandbox Code Playgroud)

构建Python3.7.3:

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar xzf Python-3.7.2.tgz && 
cd Python-3.7.2
export LD_LIBRARY_PATH=/usr/local/lib && \
export LD_RUN_PATH=/usr/local/lib && \
./configure --enable-optimizations --prefix=/usr/ --with-ensurepip=install --enable-shared LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I /usr/local/lib/libffi-3.2.1/include"
make
make install
Run Code Online (Sandbox Code Playgroud)