[英]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:我试图安装
pcapy
使用pip install pcapy
,但我encoutered一个错误,说明该文件pcap.h
不存在如下:
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.我尝试升级
setuptools
但得到了相同的结果。 I tried to install libcap
by running pip install libcap
but I also got the same problem.我试图通过运行
pip install libcap
来安装libcap
,但我也遇到了同样的问题。 How can I fix this problem?我该如何解决这个问题?
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
我们先来看看这个具体的行
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 compilepcapdumper.cc and the location is expected to be c:\\wpdpack
.正如你在那里看到的,当 pip 安装时,setup.py 会尝试使用winpcap作为依赖来编译pcapdumper.cc并且位置应该是
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:.要使其工作,您只需要下载并提取最新的稳定的 winpcap 库版本(即:不是 beta 后缀)并在 c: 上解压缩它。 Then you just open a visual command prompt and try again
pip install pcapy
.然后您只需打开一个可视化命令提示符并再次尝试
pip install pcapy
。
On my case I've tried using vs2015+python3.6.x and it's been built smoothly.在我的情况下,我尝试使用 vs2015+python3.6.x 并且它构建得很顺利。 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.另外,最后一个提示,我建议您看一下这个答案,它非常简要地解释了每次要安装像 pcapy 这样棘手的库时如何进行。
It's generally easier to download install a binary.下载安装二进制文件通常更容易。 If you do build from source:
如果您确实从源代码构建:
Download the WinPcap Developer's Pack .下载WinPcap 开发人员包。
Use pip's --global-option.使用 pip 的 --global-option。 setup.py is different, but I think pip is preferred over setup.py anyway.
setup.py 是不同的,但我认为 pip 无论如何都比 setup.py 更受欢迎。
Here's an example line (substitute in the correct paths for your system; I just referenced them right in the Downloads folder):这是一个示例行(替换为您系统的正确路径;我只是在下载文件夹中引用了它们):
pip install ./pcapy-src-dir --global-option=build_ext --global-option="-LC:\path\to\WpdPack_4_1_2\WpdPack\Lib" --global-option="-IC:\path\to\WpdPack_4_1_2\WpdPack\Include
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.