"sudo pip install cffi" fails under Ubuntu 12.04 LTS

Issue #38 invalid
CALIN BRABANDT
created an issue

Downloading/unpacking cffi Running setup.py egg_info for package cffi

Downloading/unpacking pycparser (from cffi) Running setup.py egg_info for package pycparser

Downloading/unpacking ply (from pycparser->cffi) Running setup.py egg_info for package ply

Installing collected packages: cffi, pycparser, ply Running setup.py install for cffi building '_cffi_backend' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-i686-2.7/c/_cffi_backend.o c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1 Complete output from command /usr/bin/python -c "import setuptools;file='/usr/lib/python2.7/build/cffi/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --single-version-externally-managed --record /tmp/pip-AasXUK-record/install-record.txt: running install

running build

running build_py

running build_ext

building '_cffi_backend' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-i686-2.7/c/_cffi_backend.o

c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

after copying all the .h files to /usr/include/python2.7, it fails with

Downloading/unpacking cffi Running setup.py egg_info for package cffi

Downloading/unpacking pycparser (from cffi) Running setup.py egg_info for package pycparser

Downloading/unpacking ply (from pycparser->cffi) Running setup.py egg_info for package ply

Installing collected packages: cffi, pycparser, ply Running setup.py install for cffi building '_cffi_backend' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-i686-2.7/c/_cffi_backend.o In file included from c/_cffi_backend.c:13:0: /usr/include/python2.7/ffi.h:192:6: warning: function declaration isn’t a prototype [-Wstrict-prototypes] /usr/include/python2.7/ffi.h:205:11: warning: function declaration isn’t a prototype [-Wstrict-prototypes] /usr/include/python2.7/ffi.h:279:3: warning: function declaration isn’t a prototype [-Wstrict-prototypes] c/_cffi_backend.c: In function ‘ctypedescr_new’: c/_cffi_backend.c:210:5: warning: implicit declaration of function ‘PyObject_GC_NewVar’ [-Wimplicit-function-declaration] c/_cffi_backend.c:210:47: error: expected expression before ‘CTypeDescrObject’

Comments (15)

  1. Armin Rigo

    You need to install the package "python-dev" before you can do that (I think it's the name on Ubuntu). You only installed "python". This answer is generic: you'd get the same error with any 3rd-party Python package, not just CFFI.

  2. CALIN BRABANDT reporter

    "pip install nesoni" was successful without python-dev

    However, based on your suggestion, I installed python-dev and attempted to pip install cffi again. Now I get the following fatal error. Should I resubmit another bug report?

    In file included from c/_cffi_backend.c:202:0:
    c/wchar_helper.h: In function ‘_my_PyUnicode_AsSingleWideChar’:
    c/wchar_helper.h:83:5: error: unknown type name ‘Py_UNICODE’
    c/wchar_helper.h:83:5: warning: implicit declaration of function ‘PyUnicode_AS_UNICODE’ [-Wimplicit-function-declaration]
    c/wchar_helper.h:83:21: warning: initialization makes pointer from integer without a cast [enabled by default]
    c/wchar_helper.h:84:5: warning: implicit declaration of function ‘PyUnicode_GET_SIZE’ [-Wimplicit-function-declaration]
    c/wchar_helper.h: In function ‘_my_PyUnicode_AsWideChar’:
    c/wchar_helper.h:118:5: error: unknown type name ‘Py_UNICODE’
    
  3. Armin Rigo

    Sorry, I am relying on other people like Changbin Liu to chime in. "pip install cffi" works as intended for me on all machines I tried it on, so I don't know why it doesn't work for you. Maybe paste the detailed, line-by-line commands you try to run, and the complete and untruncated output you get.

  4. Changbin Liu

    I was installing OpenStack Swift 1.11.0 which depends on cffi 0.8.1. The OS is Ubuntu 12.04.3 LTS 3.2.0-54-virtual x86_64. For me, "sudo apt-get install libffi-dev" solved the dependency problem of cffi.

    Error log in installing cffi when libffi-dev was not available:

    $ pip install cffi

    Downloading/unpacking cffi Downloading cffi-0.8.1.tar.gz (195Kb): 195Kb downloaded Running setup.py egg_info for package cffi

    Downloading/unpacking pycparser (from cffi) Downloading pycparser-2.10.tar.gz (206Kb): 206Kb downloaded Running setup.py egg_info for package pycparser

    Installing collected packages: cffi, pycparser Running setup.py install for cffi building '_cffi_backend' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DUSETHREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-2.7/c/_cffi_backend.o c/_cffi_backend.c:14:17: fatal error: ffi.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1 Complete output from command /usr/bin/python -c "import setuptools;file='/etc/swift/build/cffi/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-nFqBIE-record/install-record.txt: running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-2.7

    creating build/lib.linux-x86_64-2.7/cffi

    copying cffi/lock.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/model.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/init.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/verifier.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/api.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/gc_weakref.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/commontypes.py -> build/lib.linux-x86_64-2.7/cffi

    copying cffi/cparser.py -> build/lib.linux-x86_64-2.7/cffi

    running build_ext

    building '_cffi_backend' extension

    creating build/temp.linux-x86_64-2.7

    creating build/temp.linux-x86_64-2.7/c

    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-2.7/c/_cffi_backend.o

    c/_cffi_backend.c:14:17: fatal error: ffi.h: No such file or directory

    compilation terminated.

    error: command 'gcc' failed with exit status 1


    Command /usr/bin/python -c "import setuptools;file='/etc/swift/build/cffi/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --single-version-externally-managed --record /tmp/pip-nFqBIE-record/install-record.txt failed with error code 1 Storing complete log in /root/.pip/pip.log

  5. Armin Rigo

    What if you do "pip install pymysql" and you didn't do previously "apt-get install mysql-dev"? It doesn't work. Can we do anything about it? Not that I know of.

    From the documentation: """on CPython you need to build the C extension module, so you need python-dev and libffi-dev (for Windows, libffi is included with CFFI)."""

  6. Log in to comment