classification
Title: make install fails: no module _ctypes
Type: compile error Stage: resolved
Components: Build Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dandan Lee, Ma Lin, Mr. Pligin, THRlWiTi, bkline, bryanf, cstratak, dgspahn, dstufft, jwilk, martin.panter, ncoghlan, prabs003, slink, thomasahle, zach.ware
Priority: normal Keywords:

Created on 2017-09-30 23:04 by Dandan Lee, last changed 2019-07-26 21:15 by thomasahle. This issue is now closed.

Files
File name Uploaded Description Edit
query.csv dgspahn, 2018-09-08 19:50 error query
Messages (12)
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/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/__main__.py", line 4, in <module>
    ensurepip._main()
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/__init__.py", line 189, in _main
    default_pip=args.default_pip,
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ensurepip/__init__.py", 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/__init__.py", line 27, in _run_pip
    import pip
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py", line 28, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/vcs/mercurial.py", line 9, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 36, in <module>
  File "/tmp/tmpcg658x_c/pip-9.0.1-py2.py3-none-any.whl/pip/utils/glibc.py", line 4, in <module>
  File "/home/dandan/Downloads/cpython-3.7.0a1/Lib/ctypes/__init__.py", 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 <https://bugs.python.org/issue32401#msg308926> 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

Repeat:
./configure --enable-optimizations
make altinstall

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

NOTE: 
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/__init__.py", 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 "get-pip.py", line 20651, in <module>
    main()
  File "get-pip.py", line 197, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmpu88jadkc/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpu88jadkc/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpu88jadkc/pip.zip/pip/_internal/index.py", line 24, in <module>
  File "/tmp/tmpu88jadkc/pip.zip/pip/_internal/download.py", line 38, in <module>
  File "/tmp/tmpu88jadkc/pip.zip/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/usr/local/lib/python3.7/ctypes/__init__.py", 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.
msg337224 - (view) Author: Mr. Pligin (Mr. Pligin) Date: 2019-03-05 16:36
Linux Mint 19.1

sudo make altinstall

Traceback (most recent call last):
  File "/usr/src/Python-3.7.2/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/src/Python-3.7.2/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/Python-3.7.2/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/usr/src/Python-3.7.2/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/usr/src/Python-3.7.2/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/usr/src/Python-3.7.2/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 18, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py", line 38, in <module>
  File "/tmp/tmpc5nmmwk0/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/usr/src/Python-3.7.2/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1140: recipe for target 'altinstall' failed
make: *** [altinstall] Error 1
msg340492 - (view) Author: Nils Goroll (slink) Date: 2019-04-18 14:49
In case this helps: I noticed this during the build:


*** WARNING: renaming "_ssl" since importing it failed: ld.so.1: python: fatal: libssl.so.1.1: open failed: No such file or directory
*** WARNING: renaming "_hashlib" since importing it failed: ld.so.1: python: fatal: libssl.so.1.1: open failed: No such file or directory
*** WARNING: renaming "_ctypes" since importing it failed: ld.so.1: python: fatal: libffi.so.6: open failed: No such file or directory

...

Following modules built successfully but were removed because they could not be imported:
_ctypes               _hashlib              _ssl               

In my case the reason was that libffi was installed under /opt/local, so the fix was:


./configure LDFLAGS='-L/opt/local/lib -R/opt/local/lib'

and rebuild

For other users I would recommend to inspect the build output for _ctypes related errors, I am not saying that the cause is the same
msg348527 - (view) Author: Thomas Dybdahl Ahle (thomasahle) * Date: 2019-07-26 21:15
Installing libffi-dev worked for me.
History
Date User Action Args
2019-07-26 21:15:30thomasahlesetnosy: + thomasahle
messages: + msg348527
2019-06-08 19:13:08jwilksetnosy: + jwilk
2019-04-18 14:49:22slinksetnosy: + slink
messages: + msg340492
2019-03-05 16:36:39Mr. Pliginsetnosy: + Mr. Pligin
messages: + msg337224
2019-02-28 12:57:28inada.naokisetstatus: open -> closed
resolution: not a bug
stage: resolved
2019-02-28 10:49:39THRlWiTisetnosy: + THRlWiTi
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