简体   繁体   English

WindowsError: [错误 126] 找不到指定的模块

[英]WindowsError: [Error 126] The specified module could not be found

I am loading a dll in python using following code:我正在使用以下代码在 python 中加载 dll:

if os.path.exists(dll_path):
     my_dll = ctypes.cdll.LoadLibrary(dll_path)

But I am continuously getting the following error但我不断收到以下错误

WindowsError: [Error 126] The specified module could not be found WindowsError: [错误 126] 找不到指定的模块

dll is present at the specified path, but I didn't understand why I'm getting the error. dll 出现在指定的路径中,但我不明白为什么会出现错误。

Note that even if the DLL is in your path.请注意,即使 DLL 在您的路径中。 If that DLL relies on other DLLs that are NOT in your path, you can get the same error.如果该 DLL 依赖于不在您的路径中的其他 DLL,您可能会遇到相同的错误。 Windows could not find a dependency in this case.在这种情况下,Windows 找不到依赖项。 Windows is not real good at telling you what it could not find, only that it did not find something. Windows 并不擅长告诉您它找不到什么,只是告诉您它没有找到什么。 It is up to you to figure that out.由你来解决这个问题。 The Windows dll search path can be found here: http://msdn.microsoft.com/en-us/library/7d83bc18.aspx Windows dll 搜索路径可以在这里找到: http : //msdn.microsoft.com/en-us/library/7d83bc18.aspx

In my case, being sure all needed dlls were in the same directory and doing a os.chdir() to that directory solved the problem.就我而言,确保所有需要的 dll 都在同一目录中,然后对该目录执行 os.chdir() 解决了问题。

When I see things like this - it is usually because there are backslashes in the path which get converted.当我看到这样的事情时 - 通常是因为路径中有反斜杠被转换。

For example - the following will fail - because \\t in the string is converted to TAB character.例如 - 以下将失败 - 因为字符串中的 \\t 被转换为 TAB 字符。

>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:\tools\depends\depends.dll")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\tools\python271\lib\ctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "c:\tools\python271\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

There are 3 solutions (if that is the problem)有 3 种解决方案(如果这是问题所在)

a) Use double slashes... a) 使用双斜线...

>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:\\tools\\depends\\depends.dll")

b) use forward slashes b) 使用正斜杠

>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:/tools/depends/depends.dll")

c) use RAW strings (prefacing the string with r c) 使用 RAW 字符串(在字符串前面加上 r

>>> import ctypes
>>> ctypes.windll.LoadLibrary(r"c:\tools\depends\depends.dll")

While this third one works - I have gotten the impression from time to time that it is not considered 'correct' because RAW strings were meant for regular expressions.虽然这第三个有效 - 我不时得到的印象是它不被认为是“正确的”,因为 RAW 字符串用于正则表达式。 I have been using it for paths on Windows in Python for years without problem :) )多年来,我一直将它用于 Python 中 Windows 上的路径,没有问题:))

On the off chance anyone else ever runs into this extremely specific issue.. Something inside PyTorch breaks DLL loading.万一其他人遇到这个非常具体的问题.. PyTorch 内部的某些东西会破坏 DLL 加载。 Once you run import torch , any further DLL loads will fail.一旦您运行import torch ,任何进一步的 DLL 加载都将失败。 So if you're using PyTorch and loading your own DLLs you'll have to rearrange your code to import all DLLs first.因此,如果您使用 PyTorch 并加载自己的 DLL,则必须重新排列代码以首先导入所有 DLL。 Confirmed w/ PyTorch 1.5.0 on Python 3.7在 Python 3.7 上使用 PyTorch 1.5.0 确认

I met the same problem in Win10 32bit OS.我在 Win10 32 位操作系统中遇到了同样的问题。 I resolved the problem by changing the DLL from debug to release version.我通过将 DLL 从调试版本更改为发布版本解决了该问题。

I think it is because the debug version DLL depends on other DLL, and the release version did not.我认为是因为调试版本的 DLL 依赖于其他 DLL,而发布版本则没有。

If you are using GCC to compile it for Windows, it's possible that the error is because dependent libraries can't be found.如果您使用 GCC 为 Windows 编译它,则错误可能是因为找不到依赖库。

Using the -static flag if linking with GCC might fix that.如果与 GCC 链接,则使用 -static 标志可能会解决该问题。

这也可能是您忘记将 eclipse 中的工作目录设置为应用程序运行的正确本地目录。

In Windows, it's possible.在 Windows 中,这是可能的。 You will need to install: Visual C++ Redistributable for Visual Studio 2015. I had the same problem and I installed both version (Windows x86 and Windows x64).您将需要安装:Visual C++ Redistributable for Visual Studio 2015。我遇到了同样的问题,我安装了两个版本(Windows x86 和 Windows x64)。 Apparently both are necessary to make it work.显然,两者都是使其工作所必需的。

Tried to specify dll path in different ways (proposed by @markm), but nothing has worked for me.试图以不同的方式指定 dll 路径(由@markm 提出),但对我来说没有任何效果。 Fixed the problem by copying dll into script folder.通过将 dll 复制到脚本文件夹来解决此问题。 It's not a good solution, but ok for my purposes.这不是一个好的解决方案,但可以满足我的目的。

对我来说,从https://www.microsoft.com/en-us/download/details.aspx?id=53587安装 Microsoft Visual C++ 2015 Redistributable Update 3 解决了它。

if you come across this error when you try running PyTorch related libraries you may have to consider installing PyTorch with CPU only version ie if you don't have Nvidia GPU in your system.如果您在尝试运行 PyTorch 相关库时遇到此错误,您可能需要考虑使用仅 CPU 版本安装 PyTorch,即如果您的系统中没有 Nvidia GPU。

Pytorch with CUDA worked in Nvidia installed systems but not in others.带有 CUDA 的 Pytorch 在 Nvidia 安装的系统中工作,但在其他系统中不起作用。

There is a promising answer at Problem updating bokeh: [WinError 126] The specified module could not be found .Problem updates bokeh: [WinError 126] The specified module could not be found 上有一个有希望的答案。

It hints at https://github.com/conda/conda/issues/9313 .它暗示https://github.com/conda/conda/issues/9313

There, you find:在那里,您会发现:

It's a library load issue.这是一个库加载问题。 More details at github.com/conda/conda/issues/8836 You probably have a broken conda right now.更多详细信息,请访问 github.com/conda/conda/issues/8836 您现在可能有一个损坏的 conda。 You can use a standalone conda from repo.anaconda.com/pkgs/misc/conda-execs to repair it: standalone-conda.exe update -p C:\\ProgramData\\Anaconda3 conda-package-handling You should get version 1.6.0, and the problems should go away.您可以使用来自 repo.anaconda.com/pkgs/misc/conda-execs 的独立 conda 来修复它:standalone-conda.exe update -p C:\\ProgramData\\Anaconda3 conda-package-handling 你应该得到版本 1.6.0 ,问题应该会消失。

Thus, it might simply be a conda issue.因此,它可能只是一个 conda 问题。 Reinstalling standalone conda might repair the error.重新安装独立 conda 可能会修复错误。 Please comment whoever can confirm this.请评论谁能证实这一点。

problem solved for me.问题为我解决了。 I changed version from pytorch=1.5.1 to pytorch=1.4 and typed the below command in anaconda prompt window我将版本从 pytorch=1.5.1 更改为 pytorch=1.4 并在 anaconda 提示窗口中键入以下命令

conda install pytorch==1.4.0 torchvision==0.5.0 -c pytorch

NestedCaveats solution worked for me. NestedCaveats 解决方案对我有用。

Imported my .dll files before importing torch and gpytorch, and all went smoothly.在导入 torch 和 gpytorch 之前导入了我的 .dll 文件,一切顺利。

So I just want to add that its not just importing pytorch but I can confirm that torch and gpytorch have this issue as well.所以我只想补充一点,它不仅仅是导入 pytorch,而且我可以确认 torch 和 gpytorch 也有这个问题。 I'd assume it covers any other torch-related libraries.我认为它涵盖了任何其他与火炬相关的库。

This is probably because a runtime dependency of one of the DLLs was not found on your system.这可能是因为在您的系统上找不到其中一个 DLL 的运行时依赖项。 I think that the expected Microsoft Visual C runtime DLL is missing from your system.我认为您的系统缺少预期的 Microsoft Visual C 运行时 DLL。

Install this:安装这个:

https://www.microsoft.com/en-US/download/details.aspx?id=40784 https://www.microsoft.com/en-US/download/details.aspx?id=40784

I fixed this issue by installing VC redistributable for Visual Studio 2012 and the up-to-date Visual Studio versions.我通过为 Visual Studio 2012 和最新的 Visual Studio 版本安装 VC redistributable 解决了这个问题。 After reboot, the problem has gone.重新启动后,问题消失了。

检查你的dll名称..它不能包含任何大写字母..它必须包含所有小写字符才能成功编译

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WindowsError: [错误 126] 使用 python3.7.5 找不到指定的模块 - WindowsError: [Error 126] The specified module could not be found with python3.7.5 Python-Pymediainfo模块[错误126]找不到指定的模块 - Python - Pymediainfo Module [Error 126] The specified module could not be found 错误ctypes OSError:[WinError 126]找不到指定的模块 - error ctypes OSError: [WinError 126] The specified module could not be found Pycharm 错误 - OSError: [WinError 126] 找不到指定的模块 - Pycharm error - OSError: [WinError 126] The specified module could not be found OSError: [WinError 126] 找不到指定的模块? - OSError: [WinError 126] The specified module could not be found? WindowsError: [错误 127] 找不到指定的过程 - WindowsError: [Error 127] The specified procedure could not be found 在Python中加载模块时出错:OSError:[WinError 126]找不到指定的模块 - Error when loading module in Python: OSError: [WinError 126] The specified module could not be found Python 3.7.7 中的错误模块 Datawig 0.1.12:OSError:[WinError 126] 找不到指定的模块 - Error module Datawig 0.1.12 in Python 3.7.7: OSError: [WinError 126] The specified module could not be found 为什么会出现此错误:“OSError: [WinError 126] 找不到指定的模块”? - Why do i get this error: "OSError: [WinError 126] The specified module could not be found"? 加载 scipy 时出错:OSError: [WinError 126] 找不到指定的模块 - Error when loading scipy: OSError: [WinError 126] The specified module could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM