I'm trying to install python3 for one of remote hosting over ssh. I don't have root access. Installation was done with:

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xvzf Python-3.4.3.tgz
./configure --prefix=$HOME/.local
make install

This installs Python 3, however in the end of installation this error occurs:

File "/home/someusername/Python-3.7.0/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

python3 is installed, but pip install failed. After some research it seems that libffi is missing. After using wget to obtain libffi-3.2.1, it is installed with:

./configure --prefix=$HOME/.local
make install

This shows it is installed:

someusername@a2plcpnl079 [~/.local/lib]$ ls
./  ../  libffi-3.2.1/  libpython3.7m.a*  pkgconfig/  python3.7/
someusername@a2plcpnl079 [~/.local/lib]$ cd libffi-3.2.1/
someusername@a2plcpnl079 [~/.local/lib/libffi-3.2.1]$ ls
./  ../  include/
someusername@a2plcpnl079 [~/.local/lib/libffi-3.2.1]$ cd include
someusername@a2plcpnl079 [~/.local/lib/libffi-3.2.1/include]$ ls
./  ../  ffi.h  ffitarget.h
someusername@a2plcpnl079 [~/.local]$ cd lib64
someusername@a2plcpnl079 [~/.local/lib64]$ ls
./  ../  libffi.a  libffi.la*  libffi.so@  libffi.so.6@  libffi.so.6.0.4*

Now it is necessary to reconfigure the build of python-3.7.0 so it uses the local libffi. I tried a number of variations but still can't install pip.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

# User specific environment and startup programs


export PATH
export HISTTIMEFORMAT="%d/%m/%y %T "
export PATH="$HOME/.local/bin:$PATH"
export LD_LIBRARY_PATH=$HOME/.local/lib64

Something like this was attempted:

$ ./configure --with-system-ffi --prefix=$HOME/.local LDFLAGS="-L/home/someusername/.local/lib64" LIBS="-L/home/someusername/.local/lib"

The same error occurred, so the question is how to correctly invoke Python-3.7.0 configure to use the local libffi library in order to fully install python?

  • I've recently done a bunch of building of things that need different libraries than were installed on the system. I find it much easier to build the target binaries with static libraries than to sort out using dynamic libraries.
    – kbulgrien
    Jul 24, 2018 at 15:08

1 Answer 1


If you're fine with not having pip bundled with Python installation (the one that is accessible via python -m pip), you can deselect it with configure --without-ensurepip. By doing this, you won't need libffi for building Python. After the installation, install pip as usual python package e.g. with easy_install pip, or by downloading and executing get-pip.py.

However, you should be able to build using a custom libffi. My proposal, untested:

$ export LD_LIBRARY_PATH=$HOME/.local/lib64
$ export LD_RUN_PATH=$HOME/.local/lib64
$ ./configure --prefix=$HOME/.local LDFLAGS="-L$HOME/.local/lib64" CPPFLAGS="-I $HOME/.local/lib/libffi-3.2.1/include"
$ make
$ make install

Optional: before running make install, consider executing the tests: make test, this may uncover further errors or missing libs.

  • I tried to build with custom libffi but unfortunately it gave me same error I tried also add -R with path flag to CFLAGS but still same, guess I will need to install it separately.
    – ZeroVash
    Jul 24, 2018 at 13:56
  • Hmm, can you paste the build log to pastebin.org?
    – hoefling
    Jul 24, 2018 at 14:54
  • pastebin.com/kfUfXfFP here the config and make, without make install since in the end of make he already shows that he failed to build library
    – ZeroVash
    Jul 24, 2018 at 15:13
  • 1
    Can you try it once again, but with CPPFLAGS instead of CFLAGS, will it make any difference?
    – hoefling
    Jul 28, 2018 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .