I'm trying to build Python-3.7.3 from source with ensurepip
but i'm getting this error:
ModuleNotFoundError: No module named '_ctypes'
All of the answers online say that libffi-dev
is needed but I have it installed and it still giving me this error.
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
The build is in a container image from ubuntu:10.04
.
It is that old on purpose because I'm using PyInstaller to compile the application and it needs to run on machines with an old glibc (2.11) and this image is the only one that I could find that have this old version.
I have done the same for Python-2.7.16 and it worked without any issues.
Update Python-3.6.8 is working without any issues as well
I was able to find a solution here
The issue is probably with an old version of libffi-dev, the solution is to build and install libffi from source and then build Python3.7.3
Build 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
Build 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
This is my solution on debian 6.0.60, according to Amir Rossert's solution, thanks a lot!
(1) Install libffi
tar zxf libffi-3.3.tar.gz
cd libffi-3.3
./configure
make
make install
(2) Install Python 3.8
tar zxf Python-3.8.5.tgz
cd Python-3.8.5
export LD_LIBRARY_PATH=/usr/local/lib && \
export LD_RUN_PATH=/usr/local/lib && \
./configure --prefix=/usr/local/python38 --with-openssl=/usr/local/openssl111 --enable-shared --enable-optimizations --with-system-ffi=/usr/local/lib/
make
make install
ln -s /usr/local/python38/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python38/bin/pip3 /usr/local/bin/pip3
touch /etc/ld.so.conf/python38.conf
echo "/usr/local/python38/lib" > /etc/ld.so.conf/python38.conf
ldconfig
Ok, it works well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With