1. 安装tdm-gcc, 把以下两个目录加入PATH
TDM-GCC-64\bin
TDM-GCC-64\x86_64-w64-mingw32\bin
2. 安装WinPython
WinPython-64bit-2.7.10.1\python-2.7.10.amd64 加入PATH
3. 下载theano,解压后执行
python setup.py develop
应该很快搞定
4.cmd输入python,然后import theano,会等一会才有反应,但不应该有错误或者警告
5. 确认cpu启用
在用户目录下新建.theanorc文件,内容如下
[global]
device = cpu
force_device = True
[gcc]
cxxflags = -IC:\installed\Anaconda\MinGW\
官网的代码,结果应该是一样的,速度应该是接近的 (不过似乎每次运行时间不是固定的???)
import numpy as np
import time
import theano
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(), )
=======================================================================
anaconda似乎也可以,但除了以上步骤之外,还需要一个额外的操作
conda install mingw libpython
但这一步在我这里下载速度太慢,所以放弃了
anaconda的步骤如下
1. 安装anaconda
2. conda install mingw libpython
3. 下载https://github.com/Theano/Theano,解压后取出其中的theano文件,放到C:/anaconda/Lib/site-packages目录中
4. 修改环境变量
C:/Anaconda/MinGW/bin;C:/Anaconda/MinGW/x86_64-w64-mingw32/lib 加入 path中(确定二者之前没有其他g++路径,否则import theano时会遇到编译失败, 在CMD中
打印path检查以下,我遇到的就是cygwin中的g++在二者之前....)
新建环境变量: PYTHONPATH: C:/Anaconda/Lib/site-packages/theano;
5. 在cmd默认的启动目录新建.theanorc文件,内容如上
6. 进入python,试试import theano
=======================================================================
验证BLAS是否安装成功。由于numpy是依赖BLAS的,如果BLAS没有安装成功,虽然numpy亦可以安装,但是无法使用BLAS的加速。验证numpy是否真的成功依赖BLAS编译,用以下代码试验: