-1

I am getting this error when I run import darknet:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\darknet-master\build\darknet\x64\darknet.py", line 211, in <module>
    lib = CDLL(winGPUdll, RTLD_GLOBAL)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\darknet-master\build\darknet\x64\yolo_cpp_dll.dll' (or one of its dependencies). Try using the full path with constructor syntax.```
Seeyaq
  • 3
  • 1
  • 5
  • Could you explan how you installed `darknet`? It seems to be a local path. – astrochun Feb 16 '21 at 05:09
  • I follow this tutorial https://youtu.be/sUxAVpzZ8hU but with cuda 11 2 and opencv 4.5.1 – Seeyaq Feb 16 '21 at 05:15
  • If i import cv2 before importing darknet i don't get that error. The only error I get is name 'DARKNET_FORCE_CPU' is not defined – Seeyaq Feb 16 '21 at 05:18

4 Answers4

2

Instead of just downloading yet another version of python (yawn), we can fix darknet.py to import the DLLs correctly. As mentioned here, we need to add correct DLL import paths if using python > 3.8. The solution is to add these lines

os.add_dll_directory('c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin')
os.add_dll_directory(os.path.dirname(__file__))

somewhere before the CDLL calls. You can place them at the top of the script.

The first line allows python to load DLLs from your CUDA install which you need if you're using GPU.

The second line allows python to load DLLs from the current working directory (into which you should copy yolo_cpp_dll.dll and pthreadVC2.dll). Alternatively you could replace this to the path that contains these DLLs.

travisjayday
  • 784
  • 6
  • 16
2
lib = CDLL(winGPUdll, RTLD_GLOBAL, winmode=0)

Add the winmode=0 if python > 3.8

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '22 at 19:41
1

This is because Python 3.9 has some issue. It throws an error when the yolo_cpp_dll.dll file is imported.

Here's how to fix it:

  1. Install Python 3.7 or lower (3.6 worked for me). You can either install version 3.7 along with your current version or remove the current one and install Python 3.7 only. If installed alongside current version then you'll have to rename the newly installed python (3.7) exe file to something like python3.7 in its installed location.
  2. After renaming, add that directory to the PATH environment variable in Windows.
  3. Go to your file location where darknet is stored, (for me it's C:\Users\ARYA\Documents\Penelitian1\coba1_darknet\darknet-master\build\darknet\x64\), open the Command Prompt and type python3.7 (rather than python only). This will open Python 3.7.
  4. Here you can now run import darknet.
Anonymous
  • 738
  • 4
  • 14
  • 36
0

The answer above of @xiang zhang worked for me by adding winmod=0 in the lines 214, 218 and 222.

if not os.path.exists(winGPUdll):
    raise ValueError("NoDLL")
    lib = CDLL(winGPUdll, RTLD_GLOBAL, winmode=0)
except (KeyError, ValueError):
    hasGPU = False
    if os.path.exists(winNoGPUdll):
          lib = CDLL(winNoGPUdll, RTLD_GLOBAL, winmode=0)
          print("Notice: CPU-only mode")
    else:
    # Try the other way, in case no_gpu was compile but not renamed       
          lib = CDLL(winGPUdll, RTLD_GLOBAL, winmode=0)
Tulip89
  • 1
  • 1