Usman Ghani Mughal
Usman Ghani Mughal

Reputation: 643

OSError: [WinError 126] The specified module could not be found (using (pcap-ct) import pcap in python)

I am working on a project in which I am using libpcap and pcap-ct using python in pycharm. My code was working fine but I have to transfer my project from one device to another. Both devices are running windows 10 pro with the same version. and I am using python 3.7.3 on both devices with the same pychram version, but on the first device, my project is running fine but on the second device I am getting this error.

I am importing like this.

import pcap
import dpkt

and error is this.

    File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\ShowGraph.py", line 5, in <module>
        import pcap
    File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\pcap\__init__.py", line 6, in <module>
        from ._pcap     import * ; del _pcap      # noqa
  File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\pcap\_pcap.py", line 20, in <module>
    from libpcap import (DLT_NULL,   DLT_EN10MB, DLT_EN3MB,   DLT_AX25,
  File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap\__init__.py", line 7, in <module>
    from ._pcap      import * ; del _pcap      # noqa
  File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap\_pcap.py", line 73, in <module>
    from ._dll      import dll
  File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap\_dll.py", line 10, in <module>
    raise exc
  File "C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap\_dll.py", line 8, in <module>
    dll = DLL(DLL_PATH)
  File "C:\Users\Desktop\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

I have checked in my this directory C:\Windows\System32 I have this file wpcap.dll

I don't know, on my both devices this file is the same or not but it is present on both devices. I have search about this error code WinError 126 and found the different question and their answers but they are because someone is importing any .dll file or using it and they use \ in path and answers are they should use / or \ instead because \ are also used in Escape sequences. But I am not using anything like this.
If pcap code is using like this I don't know. can anyone help me what is the issue and what is the solution?

Upvotes: 1

Views: 861

Answers (1)

Joe
Joe

Reputation: 547

The issue is not with pcap itself, but one if its dependencies libpcap. Since I do not have access to your computer, I cannot tell what is causing the issue for certain. However, here are some troubleshooting steps I recommend:

  1. Edit C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap_dll.py line 8 so that it prints the DLL_PATH variable. This will tell you where libpcap is looking for wpcap.dll.
  2. The wpcap.dll is included with the libpcap package. Try updating the PATH environment variable so that the wpcap.dll directory is included. It will be something like this set PATH=C:\Users\Desktop\Desktop\NetworkTraficAnalyser\venv\lib\site-packages\libpcap\_platform\_windows\x64\wpcap;%PATH% See libpcap's github page for details.
  3. If those steps fail create an issue on libpcap's github page and ask for their help.

I've encountered similar errors while working with the ctypes library. They are almost always a result of searching for the wrong dll or not having the right working directory to find all the dll's dependencies.

Upvotes: 1

Related Questions