Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need hook for pypcap on windows #512

Open
jackadam1981 opened this issue Feb 8, 2018 · 11 comments
Open

Need hook for pypcap on windows #512

jackadam1981 opened this issue Feb 8, 2018 · 11 comments
Labels
good first issue Good for newcomers

Comments

@jackadam1981
Copy link

jackadam1981 commented Feb 8, 2018

i try build exe with pyinstaller.

the test.py is
print('hello')

the warntest.txt

missing module named resource - imported by posix, D:\PythonTest\\test.py
missing module named posix - imported by os, D:\PythonTest\\test.py
missing module named _posixsubprocess - imported by subprocess, D:\PythonTest\\test.py
missing module named 'org.python' - imported by pickle, D:\PythonTest\\test.py, xml.sax
missing module named readline - imported by cmd, code, pdb, D:\PythonTest\\test.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _winreg - imported by platform, D:\PythonTest\\test.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\PythonTest\\test.py
missing module named 'java.lang' - imported by platform, D:\PythonTest\\test.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\PythonTest\\test.py
missing module named termios - imported by tty, D:\PythonTest\\test.py, getpass
missing module named grp - imported by shutil, tarfile, D:\PythonTest\\test.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, D:\PythonTest\\test.py, netrc, getpass
missing module named _dummy_threading - imported by dummy_threading, D:\PythonTest\\test.py
missing module named org - imported by copy, D:\PythonTest\\test.py

dist test.exe work on some computer.

then i try add code with pypcap:

import pcap
pc = pcap.pcap()
for d,b in pc:
    print(d,b)

pyinstaller test.py

the warntest.txt same old one. no missing pcap or pypcap.
missing module named resource - imported by posix, D:\PythonTest\\test.py
missing module named posix - imported by os, D:\PythonTest\\test.py
missing module named _posixsubprocess - imported by subprocess, D:\PythonTest\\test.py
missing module named org - imported by pickle, D:\PythonTest\\test.py
missing module named readline - imported by cmd, code, pdb, D:\PythonTest\\test.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _winreg - imported by platform, D:\PythonTest\\test.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\PythonTest\\test.py
missing module named 'java.lang' - imported by platform, D:\PythonTest\\test.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\PythonTest\\test.py
missing module named termios - imported by tty, D:\PythonTest\\test.py, getpass
missing module named grp - imported by shutil, tarfile, D:\PythonTest\\test.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, D:\PythonTest\\test.py, netrc, getpass
missing module named _dummy_threading - imported by dummy_threading, D:\PythonTest\\test.py
missing module named 'org.python' - imported by copy, D:\PythonTest\\test.py, xml.sax

dist test.exe worked on my build computer.
the other computer prompt DLL load failed:

PS C:\Users\Jack\Desktop\dist\test> .\test.exe
hello
Traceback (most recent call last):
  File "test.py", line 10, in <module>
  File "D:\PythonEnvi\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
ImportError: DLL load failed: 找不到指定的模块。
[2360] Failed to execute script test

the line 10 is :
import pcap

so i try other way :
pyinstaller.exe --hidden-import pcap test.py
pyinstaller.exe -p D:\PythonEnvi\Lib\site-packages --hidden-import pcap D:\PythonTest\test.py

https://github.com/pynetwork/pypcap
the pcap homepage.

windows10 Home 64bit
python 3.63
pyinstaller 3.3.1
pypcap 1.20
npcap 0.98 installer
npcap sdd 0.1
Microsoft Visual C++ Build Tools 2015

@htgoebel
Copy link
Member

htgoebel commented Feb 8, 2018

This looks like not all required files are packages. Please have a look at Make sure everything is packaged correctly for tips to find out what is missing. Esp use NTstrace to find which dll is missing.

We would appreciate if you'd submit a hook for this. See https://pyinstaller.readthedocs.org/en/latest/hooks.html for more information about how to implement hooks.

@jackadam1981
Copy link
Author

my englist is bad.
can't understand hooks.
so try get some help.

@josephalway
Copy link

josephalway commented Feb 9, 2018

Did you install the Windows 10 SDK?

I'm pretty sure I had the same issue with an executable not running on a different computer when I hadn't included the ucrt files:

Update the pathex line in your spec file to include the ucrt dlls.

x86: (32-bit windows)
pathex=['C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\ucrt\\DLLs\\x86']

x64: (64-bit windows)
pathex=['C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\ucrt\\DLLs\\x64']

@jackadam1981
Copy link
Author

jackadam1981 commented Feb 10, 2018

Accidentally ,I solved the problem.
pypcap need npcap and winpcap API.
different computer install npcap with winpcapAPI。
then build exe work on different computer。
my script use pyqt pypcap.
i want start gui first.
then check npcap.

but,build time, import pcap.
start exe ,check import ,so DLL load failed.
mybe some ,i try included the DLL in exe.

@htgoebel htgoebel reopened this Mar 15, 2018
@htgoebel htgoebel changed the title pyinstall cannot build pypcap in windows 10 64bit。 Need hook for pypcap on windows Mar 15, 2018
@htgoebel htgoebel added the good first issue Good for newcomers label Mar 15, 2018
@arossert
Copy link
Contributor

Can anyone tell me if this is possible?
I'm trying to bundle a winpcap app ut cannot understand how to include the dlls.

@htgoebel
Copy link
Member

@arossert See above: You need to create a hook.

@arossert
Copy link
Contributor

@htgoebel thanks for the response but can you please point me to how can I achieve this with a hook?

From this conversation, it is hard to understand what needs to be done.
I have created some hooks to some modules but all of them was to include some modules or source files and never external DLLs, so I'm a bit confused about how to begin.

@htgoebel
Copy link
Member

Just read hte manual an look at other hooks. You need to add the dll as binaries.

@arossert
Copy link
Contributor

@htgoebel I have tried to manually copy the files that are installed from Npcap to the target PyInstaller directory but still getting the DLL error exception.
The files are Packet.lib & wpcap.lib, do you have any idea how to make it work?
This is the simple example that i'm trying to build:

import pcapy

if the target machine has no Npcao/winpcap installed it is throwing the DLL exception.

@bjones1
Copy link

bjones1 commented Aug 12, 2019

You don't need .lib files (static libraries used to compile an application), but the .dll files.

@arossert
Copy link
Contributor

arossert commented Aug 13, 2019

@bjones1 thanks, this was my mistake.
I have successfully created a hook that takes the Packet.dll & wpcap.dll from the system32 lib and includes them in the final directory but when I copied it to another machine it is not working, I'm getting this error:

pcapy.PcapError: No valid interfaces to open

If I install the winpcap/npcap library and remove the DLLs from my application directory it is working so I'm not sure that it is even possible.

It might be because I have built it on win7 and tested it on win10, is there a way to make it portable?

UPDATE:
I have tried to build on Win10 and run on another Win10 and it is still not working, I believe that the DLLs are not the only thing that is needed in order to "sniff" the network interfaces and that the winpcap/npcap libraries are doing something to make it work.

I wanted a way to include everything and not instruct the users of my application to install another library in order to use it.

If there is anything else that I can do to make it work I'm willing to spend the time testing it but currently I'm stuck.

@bwoodsend bwoodsend transferred this issue from pyinstaller/pyinstaller Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants