Title: make install fails: no module _ctypes
Type: compile error Stage:
Components: Build Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dandan Lee, Ma Lin, bkline, bryanf, cstratak, dgspahn, dstufft, martin.panter, ncoghlan, prabs003, zach.ware
Priority: normal Keywords:

Created on 2017-09-30 23:04 by Dandan Lee, last changed 2018-09-19 12:58 by cstratak.

File name Uploaded Description Edit
query.csv dgspahn, 2018-09-08 19:50 error query
Messages (9)
msg303434 - (view) Author: Dandan Lee (Dandan Lee) Date: 2017-09-30 23:04
The make install step fails with this error:

Traceback (most recent call last):
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/", line 85, in _run_code
    exec(code, run_globals)
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/", line 4, in <module>
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/", line 189, in _main
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/", line 102, in bootstrap
    _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/", line 27, in _run_pip
    import pip
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/", line 28, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/vcs/", line 9, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/", line 36, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/utils/", line 4, in <module>
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1080: recipe for target 'install' failed
make: *** [install] Error 1

Am I missing something?
msg303444 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2017-10-01 02:06
I expect that the root cause is missing libffi(-dev[el]) on your system, preventing _ctypes from building, so your quick fix would be to install that and try again.

However, not having _ctypes shouldn't cause installation to fail.  Donald, is ctypes a hard requirement for pip to install itself?  If so, ensurepip as called by `make install` should either gracefully handle a lack of ctypes or be disabled when ctypes is not available.
msg321216 - (view) Author: Bob Kline (bkline) * Date: 2018-07-07 12:08
Confirming that this is still failing with 3.7.0 released.
msg321253 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-07-08 03:43
In <> Chi-Hsuan suggests “configure --without-ensurepip” as a workaround.
msg321260 - (view) Author: Ma Lin (Ma Lin) * Date: 2018-07-08 06:33
> I expect that the root cause is missing libffi(-dev[el]) on your system

Yes, on my Ubuntu 18.04, `make` failed to compile _ctypes module.
After install libffi-dev, it was compiled successfully:

One more word, full necessary dependencies on my Ubuntu 18.04:
sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev
msg321740 - (view) Author: Bryan (bryanf) Date: 2018-07-16 15:44
Similar error on CentOS 7

ModuleNotFoundError: No module named '_ctypes'
Install --  yum install libffi-devel

./configure --enable-optimizations
make altinstall

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

The error did not stop python3.7 from operating as noted on this page. 

# python3.7
Python 3.7.0 (default, Jul 16 2018, 11:25:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello Python")
Hello Python
msg324860 - (view) Author: David Spahn (dgspahn) Date: 2018-09-08 19:50
I'm getting the same error   File "/usr/src/Python-3.7.0/Lib/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1122: recipe for target 'install' failed
make: *** [install] Error 1
Linux Mint 19
msg325746 - (view) Author: Prabhakar (prabs003) Date: 2018-09-19 11:25
Hi All,

Iam using centos 7. And as mentioned in this thread, though this error came, Iam able to go to python3.7 interpreter fine.

However, when i wanted to install pip, I get the same _ctype error as below.

So, I think, this needs to be resolved in order to use python3.7 in centos.

 File "", line 20651, in <module>
  File "", line 197, in main
  File "", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmpu88jadkc/", line 42, in <module>
  File "/tmp/tmpu88jadkc/", line 16, in <module>
  File "/tmp/tmpu88jadkc/", line 24, in <module>
  File "/tmp/tmpu88jadkc/", line 38, in <module>
  File "/tmp/tmpu88jadkc/", line 3, in <module>
  File "/usr/local/lib/python3.7/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

Looking for advice.
msg325755 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2018-09-19 12:58
As mentioned before, this is due to missing libffi-devel on a Centos 7 system. Verified it as well on one of my systems.

Could you try again, but before just do a 'yum install libffi-devel'?

Maybe a warning could be added to the install output when it can't find libffi.
Date User Action Args
2018-09-19 12:58:36cstrataksetnosy: + cstratak
messages: + msg325755
2018-09-19 11:25:12prabs003setnosy: + prabs003
messages: + msg325746
2018-09-08 19:50:20dgspahnsetfiles: + query.csv
nosy: + dgspahn
messages: + msg324860

2018-07-16 15:44:30bryanfsetnosy: + bryanf
messages: + msg321740
2018-07-08 06:33:02Ma Linsetnosy: + Ma Lin
messages: + msg321260
2018-07-08 03:43:20martin.pantersetnosy: + martin.panter
messages: + msg321253
2018-07-08 03:40:15martin.panterlinkissue34036 superseder
2018-07-08 03:35:10martin.panterlinkissue32401 superseder
2018-07-07 12:08:39bklinesetnosy: + bkline
messages: + msg321216
2017-11-21 21:01:54zach.warelinkissue32095 superseder
2017-10-01 02:06:05zach.waresetnosy: + zach.ware, ncoghlan, dstufft
messages: + msg303444
2017-09-30 23:04:21Dandan Leecreate