在编译的python exe中使用tshark
我有一个工作的Python脚本,它使用和导入Pyshark,因此可以使用Tshark。
只要我通过Pycharm运行代码,一切都很好。一旦我使用pyinstaller编译,我就会遇到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1921, in __call__
File "main.py", line 458, in get_pdu_ids
File "pyshark\capture\capture.py", line 232, in _packets_from_tshark_sync
File "asyncio\base_events.py", line 646, in run_until_complete
File "pyshark\capture\capture.py", line 396, in _get_tshark_process
File "pyshark\capture\capture.py", line 373, in _get_tshark_path
File "pyshark\tshark\tshark.py", line 30, in get_process_path
File "configparser.py", line 782, in get
File "configparser.py", line 1153, in _unify_values
configparser.NoSectionError: No section: 'tshark'
我尝试使用此修复程序,现在应该将其合并到Pyshark中,但是它没有更改任何内容: https://github.com/kiminewt/pyshark/issues/245
当然,一切都是最新的。
注意:其他所有导入的模块可完美地工作,例如Scapy。
提前致谢!
I have a working python script, which uses and imports pyshark, and therefore tshark.
As long as I run the code via pycharm, everything is fine. As soon as I use pyinstaller to compile, I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1921, in __call__
File "main.py", line 458, in get_pdu_ids
File "pyshark\capture\capture.py", line 232, in _packets_from_tshark_sync
File "asyncio\base_events.py", line 646, in run_until_complete
File "pyshark\capture\capture.py", line 396, in _get_tshark_process
File "pyshark\capture\capture.py", line 373, in _get_tshark_path
File "pyshark\tshark\tshark.py", line 30, in get_process_path
File "configparser.py", line 782, in get
File "configparser.py", line 1153, in _unify_values
configparser.NoSectionError: No section: 'tshark'
I tried to use this fix, which should as well be merged into pyshark by now, but it didn`t change anything: https://github.com/KimiNewt/pyshark/issues/245
Of course everything is up-to-date.
Note: Every other imported module works flawlessly, e.g. scapy.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管这个问题已经回答,但我也有一个类似的问题,我想分享我的解决方案。
Pyshark似乎会在当前目录中加载任何名为“ config.ini”的文件,就好像它是tshark配置文件一样。从get_process_path文档中:
的确,如果我们查看pyshark模块中的config.py,该pyshark模块被称为查找tshark目录,我们可以找到:
解决方案是重命名您的配置文件,请将其移动到子目录中,或者包括一个子目录或包括您的配置文件中的tshark和dumpcap部分如下:
Although this question has been answered, I have had a similar issue and I would like to share my solution.
It seems that pyshark will load any file named 'config.ini' in the current directory as if it were the tshark configuration file. From the get_process_path documentation:
Indeed, if we take a look at config.py in the pyshark module that is called to find the tshark directory we can find :
The solution is to either rename your configuration file, move it to a subdirectory, or include the tshark and dumpcap sections in your config file like this:
我找到了解决方案,在此处发布该解决方案以帮助如果其他人遇到相同的错误:
我必须对以下内容进行硬编码,因为编译的程序没有正确的变量(不知道为什么):
file:\ venv \ lib \ \站点包\ pyshark \ captution \ captut.py
是
一个肮脏的解决方案,不是解决问题,而是绕过问题,但它有效,但我还是想分享它。
I found the solution, posting it here to help if others get the same error:
I had to hard-code the following, as the compiled program didn`t get the variable correct (no idea why):
File: \venv\Lib\site-packages\pyshark\capture\capture.py
to
It is a dirty solution, not solving but bypassing the problem, but it works and I wanted to share it nonetheless.
尝试:
pyinstaller -collect -all pyshark -f main.py
这应该解决问题
Try:
pyinstaller --collect-all pyshark -F Main.py
This should resolve the issue