在安装配置python,安装mingw,安装theano时进行测试。在测试前,即所有环境配置完成后要重启电脑一次。测试时报出如下异常:ImportError:cannot import name 'configparser'
测试方式一:
将如下测试代码复制放到python中运行一下:
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(), )
测试方式二:
Import theano
print theano.config.blas.ldflags
通过上述两种方式进行测试,均未通过,报出如下异常:ImportError:cannot import name 'configparser'
解决方法:我修改了两个地方,然后重启电脑后,该异常信息消失。
修改处一:由于网上的教程,当时添加了一个环境变量,变量名称为:“PYTHONPATH”,变量值为“C:\Anaconda\Lib\site-packages\theano;”
的修改是将该环境变量删除,不用添加。
修改处二:修改.theanorc.txt文件。修改及部分说明如下图所示,为了方便复制,代码在最后面。
代码如下:
[global]
openmp=False
device = gpu
optimizer_including=cudnn
floatX = float32
allow_input_downcast=True
[lib]
cnmem = 0.8
[blas]
ldflags=
[gcc]
cxxflags=-IC:\Users\f\Anaconda3\MinGW
[nvcc]
flags = -LC:\Users\f\Anaconda3\libs
compiler_bindir = G:\VS\VC\bin
fastmath = True
修改上述两处后,重启电脑,报出的异常信息就没有了。