Import darknet FileNotFoundError: Could not find module
Import darknet FileNotFoundError: Could not find module
我在 运行 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.```
这是因为 Python 3.9 有一些问题。导入 yolo_cpp_dll.dll
文件时会抛出错误。
修复方法如下:
- 安装 Python 3.7 或更低版本(3.6 适合我)。您可以与当前版本一起安装 3.7 版,也可以删除当前版本并仅安装 Python 3.7。如果与当前版本一起安装,那么您必须在其安装位置将新安装的 python (3.7) exe 文件重命名为类似 python3.7 的名称。
- 重命名后,将该目录添加到 Windows 中的 PATH 环境变量中。
- 转到存储 darknet 的文件位置(对我来说是
C:\Users\ARYA\Documents\Penelitian1\coba1_darknet\darknet-master\build\darknet\x64\
),打开命令提示符并键入 python3.7(而不是仅 python)。这将打开 Python 3.7.
- 在这里你现在可以运行
import darknet
.
我们可以修复 darknet.py 以正确导入 DLL,而不是仅仅下载另一个版本的 python (yawn)。如前所述 here,如果使用 python > 3.8,我们需要添加正确的 DLL 导入路径。解决方案是添加这些行
os.add_dll_directory('c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin')
os.add_dll_directory(os.path.dirname(__file__))
CDLL 调用之前的某处。您可以将它们放在脚本的顶部。
第一行允许 python 从您的 CUDA 安装中加载 DLL,如果您使用的是 GPU,则需要这些 DLL。
第二行允许 python 从当前工作目录(您应该将 yolo_cpp_dll.dll
和 pthreadVC2.dll
复制到其中)加载 DLL。或者,您可以将其替换为包含这些 DLL 的路径。
lib = CDLL(winGPUdll, RTLD_GLOBAL, winmode=0)
如果 python > 3.8
添加 winmode=0
以上@xiang zhang的回答
通过在第 214、218 和 222 行添加 winmod=0 为我工作。
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)
我在 运行 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.```
这是因为 Python 3.9 有一些问题。导入 yolo_cpp_dll.dll
文件时会抛出错误。
修复方法如下:
- 安装 Python 3.7 或更低版本(3.6 适合我)。您可以与当前版本一起安装 3.7 版,也可以删除当前版本并仅安装 Python 3.7。如果与当前版本一起安装,那么您必须在其安装位置将新安装的 python (3.7) exe 文件重命名为类似 python3.7 的名称。
- 重命名后,将该目录添加到 Windows 中的 PATH 环境变量中。
- 转到存储 darknet 的文件位置(对我来说是
C:\Users\ARYA\Documents\Penelitian1\coba1_darknet\darknet-master\build\darknet\x64\
),打开命令提示符并键入 python3.7(而不是仅 python)。这将打开 Python 3.7. - 在这里你现在可以运行
import darknet
.
我们可以修复 darknet.py 以正确导入 DLL,而不是仅仅下载另一个版本的 python (yawn)。如前所述 here,如果使用 python > 3.8,我们需要添加正确的 DLL 导入路径。解决方案是添加这些行
os.add_dll_directory('c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin')
os.add_dll_directory(os.path.dirname(__file__))
CDLL 调用之前的某处。您可以将它们放在脚本的顶部。
第一行允许 python 从您的 CUDA 安装中加载 DLL,如果您使用的是 GPU,则需要这些 DLL。
第二行允许 python 从当前工作目录(您应该将 yolo_cpp_dll.dll
和 pthreadVC2.dll
复制到其中)加载 DLL。或者,您可以将其替换为包含这些 DLL 的路径。
lib = CDLL(winGPUdll, RTLD_GLOBAL, winmode=0)
如果 python > 3.8
添加winmode=0
以上@xiang zhang的回答 通过在第 214、218 和 222 行添加 winmod=0 为我工作。
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)