在 Windows 上安装 Theano - DLL 加载失败

问题描述 投票:0回答:6

我正在尝试在 Windwos 8 上安装 Theano

已遵循这些步骤。

我尝试使用以下方法进行测试:

import numpy as np
import time
import theano

print('blas.ldflags=', theano.config.blas.ldflags)
A = np.random.rand(1000, 10000).astype(theano.config.floatX)
B = np.random.rand(10000, 1000).astype(theano.config.floatX)
np_start = time.time()
AB = A.dot(B)
np_end = time.time()
X, Y = theano.tensor.matrices('XY')
mf = theano.function([X, Y], X.dot(Y))
t_start = time.time()
tAB = mf(A, B)
t_end = time.time()
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" % (
np_end - np_start, t_end - t_start))
print("Result difference: %f" % (np.abs(AB - tAB).max(), ))

我知道该脚本是 numpy 和 theano 计算时间之间的比较。

但不知何故,有些dll找不到。请找到以下日志:

[Py341] C:\>python ML\Deep\TheanoSetupTesting.py
blas.ldflags= -LE:\Things_Installed_Here\Theano\openblas -lopenblas
Traceback (most recent call last):
  File "ML\Deep\TheanoSetupTesting.py", line 12, in <module>
    mf = theano.function([X, Y], X.dot(Y))
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\compile\function.py", line 317, in function
    output_keys=output_keys)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\compile\pfunc.py", line 526, in pfunc
    output_keys=output_keys)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\compile\function_module.py", line 1778, in orig_function

    defaults)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\compile\function_module.py", line 1642, in create input_storage=input_storage_lists, storage_map=storage_map)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\link.py", line 690, in make_thunk
    storage_map=storage_map)[:3]
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\vm.py", line 1037, in make_all
    no_recycling))
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\op.py", line 932, in make_thunk
    no_recycling)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\op.py", line 850, in make_c_thunk
    output_storage=node_output_storage)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cc.py", line 1207, in make_thunk
    keep_lock=keep_lock)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cc.py", line 1152, in __compile__
    keep_lock=keep_lock)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cc.py", line 1602, in cthunk_factory
    key=key, lnk=self, keep_lock=keep_lock)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cmodule.py", line 1174, in module_from_key  module = lnk.compile_cmodule(location)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cc.py", line 1513, in compile_cmodule
    preargs=preargs)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cmodule.py", line 2196, in compile_str
    return dlimport(lib_filename)
  File "E:\Things_Installed_Here\Anaconda_Py\envs\Py341\lib\site-packages\theano-0.7.0-py3.4.egg\theano\gof\cmodule.py", line 331, in dlimport
    rval = __import__(module_name, {}, {}, [module_name])
ImportError: DLL load failed: The specified module could not be found.

作为Python世界的新手,我无法找出未找到哪个Dll。如果缺少,我会安装它,并将路径添加到系统路径变量中。但是我如何知道它是哪个dll呢?我尝试使用

pdb
并在
cmodule.py
的各个位置设置断点,但没有一个被击中。

  1. 您熟悉这种错误及其解决方法吗?
  2. 否则,帮我找到丢失的 dll 名称,我会完成剩下的工作。
  3. 我不介意在安装时走完全不同的道路
    theano
    。我看到几篇文章表明微软编译器工作得很好。但自过去 14 小时以来,我已经连续遇到一个问题,并且想要一种有效的方法。最终我希望在我的系统上使用
    theano

顺便说一句,没有

CUDA
。我只在 CPU 上尝试。

python dll installation theano pdb
6个回答
5
投票

这可能有点晚了。我遵循与您完全相同的指南,并遇到了相同的错误。

事实证明,可以通过将 openblas 目录添加到系统路径来修复它。在您的示例中,将“E:\Things_Installed_Here\Theano\openblas”添加到系统路径变量。

请注意,根据您放置 DLL 文件的位置,您需要添加“E:\Things_Installed_Here\Theano\openblas”或“E:\Things_Installed_Here\Theano\openblas in”。

Windows 10 64 位、Python 3.5.1 (Anaconda 2.5)、Theano 0.8.2。

对于那些需要它的人,由于这三个指南guide1guide2以及OP附带的指南,我能够在Windows 10中安装Theano。


3
投票

好吧,我终于找到了至少我使用 WinPython、python3.5.1.1、Win 7 64bit 和 mingw64 安装的原因:

在 .theanorc[.txt] 文件中,安装 blas 后,我有一个 [blas] 部分,其中一行包含 openblas 包含路径。我删除了该行并将下面的区域留为空白。重新启动 WinPython/Spider,打开一个新控制台,它就工作了。

随后使用 Theano 从 Lasagne 运行 mnist.py 进行测试。


2
投票

我也在努力让 theano 在 Windows 10 x64 上工作,在阅读了几份帮助指南后,最终对我有用的是:

  1. 安装适用于 Python 的英特尔分发版(确保 c:\intelpython27\ 和 c:\intelpython27\scripts 位于路径中)
  2. 打开命令行并执行:
    conda install mingw libpython
  3. 然后做:
    pip install theano
  4. http://sourceforge.net/projects/openblas/files/v0.2.14/下载预编译的 libopenblas.dll (我得到了 OpenBLAS-v0.2.14-Win64-int32.zip)
  5. 也从 http://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip/download
  6. 下载 mingw64_dll.zip
  7. 将 OpenBLAS-v0.2.14-Win64-int32.zip 解压到 c:\openblas,例如
  8. 将 mingw64_dll.zip 解压到 c:\openblas 中
  9. 将 c:\openblas\lib 和 c:\openblas 添加到 PATH
  10. 在c:\Users\{用户名}中创建.theanorc.txt
  11. 将以下内容放入.theanorc.txt:

    [global]
    floatX = float32
    device = cpu
    
    [blas]
    ldflags = -LC:\\openblas\\bin -LC:\\openblas\\lib -lopenblas
    

希望这对某人有帮助。


1
投票

只是补充一下我使用 Win10 64 位和 theano(和 keras)的经验。我也遇到了 DLL 加载失败错误。尝试了我在 theano win 安装网页以及不同论坛和博客文章中找到的所有内容(在 Uradium 的帖子中提到)。

它对我不起作用,但这是有效的:

  1. 我安装了TDM-GCC-64和openblas,使用regedit我已将它们的/bin目录添加到PATH(以及openblas的/lib目录)

  2. 在 miniconda3 下制作了干净的 venv - 安装了 theano 和 keras(scipy、numpy、pyyaml)、python 3.5.2

  3. 的先决条件
  4. conda install mingw libpython

  5. conda install theano
    (也安装所有 mingw 库)

  6. 此时 - 它起作用了 - 所以我没有使用任何

    .theanorc.txt
    文件配置,没有摆弄 Windows 环境变量。它甚至适用于基于 keras 的 python 脚本,尽管我没有将 keras 安装到我的 conda venv 中,但它正在工作......(我在我的“正常”非 conda python3 中安装了 keras,后来我在下面安装了 keras我的 conda venv 也是如此)。


0
投票

很晚了,但供以后参考。我偶然发现这个线程试图在 CPU 上运行 OpenBLAS 测试脚本。它在 GPU 上运行良好,但 CPU 给我带来了与 OP 相同的错误。我尝试了这里的建议,但没有用。事实证明 .theanorc 中的行:

ldflags=-LE:\OpenBLAS-v0.2.14-Win64-int32/bin -lopenblas

bin 之后和 -l 之前不应有空格。所以应该是:

ldflags=-LE:\OpenBLAS-v0.2.14-Win64-int32/bin-lopenblas

现在一切正常了。试了一下:

Windows 10
Python 3.5
Theano 0.9
Cuda 8 (with CudaMEM and CudaDNN)
Visual Studio 2015 Community

0
投票

我遇到了这个问题,我得到了这个解决方案, 安装 theano 后,我再次重新安装 numpy 。我解决了这个问题

pip 卸载 numpy

pip 安装 numpy

© www.soinside.com 2019 - 2024. All rights reserved.