Search code examples
pythonpyinstallertsharkpyshark

Using Tshark in compiled python exe


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!


Solution

  • 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

    def _get_tshark_path(self):
         return get_process_path(self.tshark_path)
    

    to

    def _get_tshark_path(self):
         return r"C:/Program Files/Wireshark/tshark.exe"
    

    It is a dirty solution, not solving but bypassing the problem, but it works and I wanted to share it nonetheless.