Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install pcapy cannot open include file 'pcap.h'

I tried to install pcapy using pip install pcapy, but I encoutered an error stating that the file pcap.h does not exist as following:

Installing collected packages: pcapy
  Running setup.py install for pcapy ... error
    Complete output from command c:\python27\python.exe -u -c "import setuptools
tokenize;__file__='c:\\users\\username\\appdata\\local\\temp\\pip-install-1tyk
yr\\pcapy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" 
install --
record c:\users\username\appdata\local\temp\pip-record-u_q6qm\install-record.txt
 --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'pcapy' extension
    creating build
    creating build\temp.win-amd64-2.7
    creating build\temp.win-amd64-2.7\Release
    creating build\temp.win-amd64-2.7\Release\win32
    C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for
Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DWIN32=1 -I
c:\wpdpack\Include -Ic:\python27\include -Ic:\python27\PC /Tppcapdumper.cc /Fobuild\temp.win-amd64-2.7\Release\pcapdumper.obj
    pcapdumper.cc
    pcapdumper.cc(11) : fatal error C1083: Cannot open include file: 'pcap.h': N
o such file or directory
    error: command 'C:\\Users\\UserName\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\username\\appdata\\local\\temp\\pip-install-1tykyr\\pcapy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\username\appdata\local\temp\pip-record-u_q6qm\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\username\appdata\local\temp\pip-install-1tykyr\pcapy\

I tried to upgrade setuptools but I got the same result. I tried to install libcap by running pip install libcap but I also got the same problem. How can I fix this problem?

like image 881
Skiller Dz Avatar asked May 31 '18 23:05

Skiller Dz


People also ask

How do I install a pcapy extension in Python?

In order to compile and install the source execute the following command from the directory where the pcapy’s distribution has been unpacked: ‘python setup.py install’. This will install the extension into the default Python’s modules path; note that you might need special permissions to write there.

Is it possible to build pcapy from the source?

From the text on the CoreLabs site for pcapy, that suggests that you downloaded the source rather than the Win32 binary. Unless you really need to build from source, you will probably find it a LOT easier to just install the binary. Do the falses there mean that WinPcap did not get installed properly?

What is libpcap in Python?

It is a replacement of Pcapy, which is not maintained any more and stopped working altogether on Python3.10. From libpcap’s documentation: “Libpcap is a system-independent interface for user-level packet capture.

Do I need to install the WinPcap developer's Pack?

Then, IF you NEED to build from source, you need to install the WinPcap Developer's Pack.


1 Answers

Let's take a look first to this specific line cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DWIN32=1 -Ic:\wpdpack\Include -Ic:\python27\include -Ic:\python27\PC /Tppcapdumper.cc /Fobuild\temp.win-amd64-2.7\Release\pcapdumper.obj

As you can see there, when pip installing, setup.py will try to use winpcap as a dependency to compile pcapdumper.cc and the location is expected to be c:\wpdpack.

To make it work you just need to download and extract the latest stable winpcap library version (ie: not beta suffix) and uncompress it on c:. Then you just open a visual command prompt and try again pip install pcapy.

On my case I've tried using vs2015+python3.6.x and it's been built smoothly. In any case, make sure you read its docs carefully, specially the part where it talks about requirements.

Also, one last hint, I recommend you take a look to this answer which explains very briefly how to proceed each time you want to install tricky libraries like this pcapy.

like image 194
BPL Avatar answered Sep 30 '22 21:09

BPL