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

5

我正在尝试在Windows 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.

作为一个新手,我不知道哪个DLL文件缺失了。如果确实缺失,我会安装它并将其路径添加到系统路径变量中。但是我该如何知道缺少的dll是哪个呢?我尝试使用pdbcmodule.py中设置断点,但是没有打中任何一个。

  1. 您是否熟悉这种错误及其解决方法?
  2. 否则,请帮我找出缺少的dll名称,我会完成剩下的步骤。
  3. 我不介意通过完全不同的安装方法来安装theano。我看过一些帖子,建议使用微软编译器就可以了。但是我已经连续14个小时遇到问题了,希望有一个可行的方法。最终我想要在我的系统上安装theano

顺便说一句,我没有CUDA。我只在CPU上进行尝试。


1
你好。我也遇到了同样的问题。实际上,在Windows 64位系统上使用Theano是一场灾难。一个问题接着一个问题,如果你的部门不允许或不使用Linux,那还有什么选择呢? - gilgamash
5个回答

5
这可能有点晚了。我按照你的指南进行了相同的操作,并遇到了相同的错误。
结果发现,通过将 openblas 目录添加到系统路径中可以解决问题。在你的例子中,将“E:\Things_Installed_Here\Theano\openblas”添加到系统路径变量中。
请注意,根据您放置 DLL 文件的位置,您需要添加“E:\Things_Installed_Here\Theano\openblas”或“E:\Things_Installed_Here\Theano\openblas\bin”。
Windows 10 64 位,Python 3.5.1(Anaconda 2.5),Theano 0.8.2。
对于那些需要的人,我能够在 Windows 10 上安装 Theano,感谢这三个指南 guide1guide2 和 OP 提供的指南。

不幸的是,我无法测试它,因为我正在享受 Linux 的世界。如果对其他人有效,请在评论中添加,随着时间的推移,这可能会成为可行的解决方案。 - Adorn

3

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

在.theanorc[.txt]文件中,我在安装完blas之后,在[blas]部分有一行包括openblas include路径的内容。我删除了那一行,将[blas]下面的区域留空。重新启动WinPython/Spider,打开一个新的控制台,然后它就可以正常工作了。

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


1
我曾尝试过这个,但对我来说没有用。我已经放弃了并转向Linux——现在速度非常快:P。感谢您的努力。 - Adorn

2

我也曾在Windows 10 x64上苦于无法使用Theano,经过阅读多篇帮助指南后,最终对我有效的方法如下:

  1. Install Intel Distribution for Python (make sure c:\intelpython27\ and c:\intelpython27\scripts are in the PATH)
  2. Open a command line and do: conda install mingw libpython
  3. Then do: pip install theano
  4. Download the precompiled libopenblas.dll from http://sourceforge.net/projects/openblas/files/v0.2.14/ (I got OpenBLAS-v0.2.14-Win64-int32.zip)
  5. Download mingw64_dll.zip as well from http://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip/download
  6. extract OpenBLAS-v0.2.14-Win64-int32.zip to c:\openblas, for example
  7. extract mingw64_dll.zip to c:\openblas\bin
  8. Add c:\openblas\lib and c:\openblas\bin to PATH
  9. Create .theanorc.txt in c:\Users\{username}
  10. Put the following in .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. conda install mingw libpython

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

  5. 此时 - 它工作了 - 所以我没有使用任何.theanorc.txt文件配置,也没有调整Windows环境变量。它甚至可以用于基于keras的Python脚本,即使我没有将keras安装到我的conda venv中,它也能正常工作...(我在"正常"的非conda Python3中安装了keras,稍后我也在conda venv中使用pip安装了keras)。


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接