'pcapdumper.cc:10:20: fatal error: Python.h: No such file or directory' via pip install

Hello!

I’m trying to install python-pcapy lib vresion 0.10.10 from

pip install pcapy

.

Packages: setuptools, python-devel, gcc-c++, libpcap-devel are already installed.

So, let’s run “pip install pcapy” command:

k_mikhail@linux-mk500:~> sudo pip install pcapy
Collecting pcapy
  Using cached pcapy-0.10.10.tgz
Installing collected packages: pcapy
  Running setup.py install for pcapy ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-it62ew3l/pcapy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
', '
'), __file__, 'exec'))" install --record /tmp/pip-783c4f7n-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'pcapy' extension
    creating build
    creating build/temp.linux-x86_64-3.4
    gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python3.4m -c pcapdumper.cc -o build/temp.linux-x86_64-3.4/pcapdumper.o
    pcapdumper.cc:10:20: fatal error: Python.h: Нет такого файла или каталога
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-it62ew3l/pcapy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
', '
'), __file__, 'exec'))" install --record /tmp/pip-783c4f7n-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-it62ew3l/pcapy/


Ok, let’s try “find / -name Python.h 2>/dev/null” command:

/usr/include/python2.7/Python.h

I’ve tried the same installation via pip on ALT Linux – everything works fine. Ok, I can install python-pcapy from devel:language:python repo, but here is 0.10.5 version, which is very old. Please, help to resolve this. Thanks!

At the same time manual compilation works fine:

k_mikhail@linux-mk500:~> sudo python setup.py install
running install
running bdist_egg
running egg_info
writing pcapy.egg-info/PKG-INFO
writing top-level names to pcapy.egg-info/top_level.txt
writing dependency_links to pcapy.egg-info/dependency_links.txt
reading manifest file 'pcapy.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pcapy.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/pcapy.so -> build/bdist.linux-x86_64/egg
creating stub loader for pcapy.so
byte-compiling build/bdist.linux-x86_64/egg/pcapy.py to pcapy.pyc
installing package data to build/bdist.linux-x86_64/egg
running install_data
creating build/bdist.linux-x86_64/egg/share
creating build/bdist.linux-x86_64/egg/share/doc
creating build/bdist.linux-x86_64/egg/share/doc/pcapy
copying README -> build/bdist.linux-x86_64/egg/share/doc/pcapy
copying LICENSE -> build/bdist.linux-x86_64/egg/share/doc/pcapy
copying pcapy.html -> build/bdist.linux-x86_64/egg/share/doc/pcapy
creating build/bdist.linux-x86_64/egg/tests
copying tests/pcapytests.py -> build/bdist.linux-x86_64/egg/tests
copying tests/96pings.pcap -> build/bdist.linux-x86_64/egg/tests
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pcapy.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pcapy.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pcapy.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pcapy.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/pcapy-0.10.10-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pcapy-0.10.10-py2.7-linux-x86_64.egg
Removing /usr/lib64/python2.7/site-packages/pcapy-0.10.10-py2.7-linux-x86_64.egg
Copying pcapy-0.10.10-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
pcapy 0.10.10 is already the active version in easy-install.pth

Installed /usr/lib64/python2.7/site-packages/pcapy-0.10.10-py2.7-linux-x86_64.egg
Processing dependencies for pcapy==0.10.10
Finished processing dependencies for pcapy==0.10.10

So, two ways give us two different results. Possibly, something should be fixed for pip here?

Hi
The pip command is wanting/using python3? Try pip3 or pip3.4?

Hi
See here: Releases · helpsystems/pcapy · GitHub

Added Python 3 Support

So it should be pip3 not pip…

ok, no problem:

k_mikhail@linux-mk500:~> sudo pip3 install pcapy
root's password:
Collecting pcapy
  Using cached pcapy-0.10.10.tgz
Installing collected packages: pcapy
  Running setup.py install for pcapy ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yomf5raj/pcapy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
', '
'), __file__, 'exec'))" install --record /tmp/pip-fvuj2oe0-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'pcapy' extension
    creating build
    creating build/temp.linux-x86_64-3.4
    gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python3.4m -c pcapdumper.cc -o build/temp.linux-x86_64-3.4/pcapdumper.o
    pcapdumper.cc:10:20: fatal error: Python.h: Нет такого файла или каталога
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yomf5raj/pcapy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
', '
'), __file__, 'exec'))" install --record /tmp/pip-fvuj2oe0-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-yomf5raj/pcapy/

:wink:

Here is from ALT Linux:

[configurator@server]$ pip show pcapy
---
Name:pcapy
Version: 0.10.10
Location: /usr/lib/python2.7/site-packages
Requires:

That means, that pcapy 0.10.10 can be also successfully installed by simple pip, not pip3, command.

Hi
Is python3-devel package installed?


 pip3 install pcapy
Collecting pcapy
  Using cached pcapy-0.10.10.tgz
Installing collected packages: pcapy
  Running setup.py install for pcapy
Successfully installed pcapy-0.10.10

Hmmm… after python3-devel package installation, the both pip and pip3 variants are valid. Fantastic! :open_mouth:

k_mikhail@linux-mk500:~> sudo zypper in python3-devel
Загрузка данных репозитария...
Чтение установленных пакетов...
Разрешение зависимостей пакетов...

The following NEW package is going to be installed:
  python3-devel

1 new package to install.
Общий размер загрузки: 133,2 KiB. Уже кэшировано: 0 B. После этой операции будет использовано дополнительно 494,7 KiB.
продолжить? [y/n/? выводит все параметры] (y): y
Получение package python3-devel-3.4.1-6.2.x86_64                                                                                                    (1/1), 133,2 KiB (494,7 KiB нераспаковано)
Получение: python3-devel-3.4.1-6.2.x86_64.rpm ........................................................................................................................................ГОТОВО]
Выполняется проверка на конфликты файлов: ............................................................................................................................................ГОТОВО]
(1/1) Устанавливается: python3-devel-3.4.1-6.2.x86_64 ................................................................................................................................ГОТОВО]

k_mikhail@linux-mk500:~> sudo pip3 install pcapy
Collecting pcapy
  Using cached pcapy-0.10.10.tgz
Installing collected packages: pcapy
  Running setup.py install for pcapy ... done
Successfully installed pcapy-0.10.10

k_mikhail@linux-mk500:~> sudo pip3 uninstall pcapy
Uninstalling pcapy-0.10.10:
  /usr/lib64/python3.4/site-packages/pcapy-0.10.10-py3.4.egg-info
  /usr/lib64/python3.4/site-packages/pcapy.cpython-34m.so
  /usr/share/doc/pcapy/LICENSE
  /usr/share/doc/pcapy/README
  /usr/share/doc/pcapy/pcapy.html
  /usr/tests/96pings.pcap
  /usr/tests/pcapytests.py
Proceed (y/n)? y
  Successfully uninstalled pcapy-0.10.10

k_mikhail@linux-mk500:~> sudo pip install pcapy
Collecting pcapy
  Using cached pcapy-0.10.10.tgz
Installing collected packages: pcapy
  Running setup.py install for pcapy ... done
Successfully installed pcapy-0.10.10

Thank you very much for your assistance! :shake:

UPD:

k_mikhail@linux-mk500:~> pip3 show pcapy
---
Metadata-Version: 1.0
Name: pcapy
Version: 0.10.10
Summary: Python pcap extension
Home-page: https://github.com/CoreSecurity/pcapy
Author: CORE Security
Author-email: oss@coresecurity.com
License: Apache modified
Location: /usr/lib64/python3.4/site-packages
Requires: 
Classifiers:


k_mikhail@linux-mk500:~> pip show pcapy
---
Metadata-Version: 1.0
Name: pcapy
Version: 0.10.10
Summary: Python pcap extension
Home-page: https://github.com/CoreSecurity/pcapy
Author: CORE Security
Author-email: oss@coresecurity.com
License: Apache modified
Location: /usr/lib64/python3.4/site-packages
Requires: 
Classifiers:

So, even pip, which is acceptable for python2.7, installs for 3.4? Why? It’s bug, as for me…

Hi
Look at pip (it’s pip3 in disguise) I would guess only python3-pip is installed, not python-pip?


which pip
/usr/bin/pip

ls -la /usr/bin/pip
lrwxrwxrwx 1 root root 21 Oct 29  2015 /usr/bin/pip -> /etc/alternatives/pip

cat /etc/alternatives/pip
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==7.1.2','console_scripts','pip3.4'
__requires__ = 'pip==7.1.2'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==7.1.2', 'console_scripts', 'pip3.4')()
    )

Seems different distros get different methods here… :dont-know: But ok, the main goal here was to force pcapy to be installed. Thanks again!

Hi
No worries, but at least it looks like we figured out why… so if you strike it again it might be time to install python-pip if the python module is not ported to python3 :wink:

Sorry, didn’t pay attention on phrase “I would guess only python3-pip is installed, not python-pip?” first. :frowning:

Seems, yes, python3-pip was installed instead of python-pip.

Now everything is fine for python-pip and pcapy 0.10.10 for 2.7:

k_mikhail@linux-mk500:~> pip show pcapy
---
Metadata-Version: 1.0
Name: pcapy
Version: 0.10.10
Summary: Python pcap extension
Home-page: https://github.com/CoreSecurity/pcapy
Author: CORE Security
Author-email: oss@coresecurity.com
License: Apache modified
Location: /usr/lib64/python2.7/site-packages
Requires: 
Classifiers:

That exactly I need. And, indeed, the program I need to install, doesn’t work with python3. Only with 2.7.

Thanks again! :shake: