Win7(32位)+Python2.7+Keras1.2.2+Theano 环境安装配置

操作步骤:

1.下载Python2.7
https://www.python.org/downloads/release/python-2718/

2.检查pip是否安装
pip一般会自带,在Python的安装目录下的Scripts的文件夹中;

若手动安装pip:

下载地址:https://pypi.python.org/pypi/pip

3.安装wheel
执行CMD命令:
C:UsersAdministrator>pip install wheel
(注:需添加系统变量C:Python27Scripts,也可以cmd里进入到Scripts文件夹,然后执行pip install wheel)
运行结果:
Successfully installed wheel-0.36.2

4.安装numpy
下载:https://pypi.org/project/numpy/1.12.1/#files
进入文件 numpy-1.12.1-cp27-none-win32.whl 所在位置位置,比如:E:
执行命令:

pip install numpy-1.12.1-cp27-none-win32.whl

运行结果:
Successfully installed numpy-1.12.1

5.安装SciPy
下载:https://sourceforge.net/projects/scipy/files/scipy/0.16.1/

进入文件 scipy-1.2.3-cp27-cp27m-win32.whl 所在位置位置比如:E:

执行命令:
pip install scipy-1.2.3-cp27-cp27m-win32.whl
运行结果:

Successfully installed  scipy-1.2.3

6.安装PyYAML
下载:http://pyyaml.org/wiki/PyYAML
进入文件 PyYAML-5.3.1-cp27-cp27m-win32.whl 所在位置位置比如:E:

执行命令:
pip install PyYAML-5.3.1-cp27-cp27m-win32.whl
运行结果:
Successfully installed PyYAML-5.3.1

7.安装Theano
下载:http://deeplearning.net/software/theano/install.html#install

如果无法下载,则使用下面地址:
https://github.com/Theano/Theano

8.安装g++的编译器,MinGW
https://sourceforge.net/projects/mingw/files/Installer/mingw-get/

非官方下载资源:https://www.lfd.uci.edu/~gohlke/pythonlibs/

(如果官方网站因VPN无法下载,使用此网址)

【调试】

执行cmd命令:

C:UsersAdministrator>python

C:UsersAdministrator>import keras

bug1:

---------------------------------------------------------------------------------------------------------------

WARNING (theano.configdefaults): g++ not available, if using conda: `conda insta
ll m2w64-toolchain`
C:Python27libsite-packages heanoconfigdefaults.py:560: UserWarning: Depreca
tionWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a
c++ compiler will be mandatory
warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
on implementations. Performance will be severely degraded. To remove this warnin
g, set Theano flags cxx to an empty string.

---------------------------------------------------------------------------------------------------------------

解决:

===============================================================

1.打开MinGW Installlation Manager
2.选中Basic Setup -> mingw32-gcc-g++
3.【Installation】->【Apply Changes】

===============================================================

bug2:

--------------------------------------------------------------------------------------------------------------------

WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
nctions.
WARNING (theano.tensor.blas): Failed to import scipy.linalg.blas, and Theano fla
g blas.ldflags is empty. Falling back on slower implementations for dot(matrix,
vector), dot(vector, matrix) and dot(vector, vector) (DLL load failed: 找不到指
定的模块。)

--------------------------------------------------------------------------------------------------------------------

解决:

==================================================================

创建.theanorc.txt文件

+++++++++++++++++++++++++++++++++++++++++++++++++++

C:UsersAdministrator>copy con .theanorc.txt
[global]
openmp=True
device=cpu
floatX=float32
allow_input_downcast=True

[blas]
ldflags = -LC:\MinGW\OpenBLAS-v0.2.7-x86-Win\lib -lopenblas

+++++++++++++++++++++++++++++++++++++++++++++++++++

==================================================================

bug3:

-------------------------------------------------------------------------------------------------------

ImportError: No module named _multiarray_umath
ImportError: No module named _multiarray_umath

-------------------------------------------------------------------------------------------------------

解决:

===========================================================

升级numpy
执行cmd命令: C:UsersAdministrator>
pip install -upgrade numpy

===========================================================

bug4:

-------------------------------------------------------------------------------------------------------

File "<stdin>", line 1
improt keras
^
SyntaxError: invalid syntax

-------------------------------------------------------------------------------------------------------

解决:

===========================================================

退出Python
执行cmd命令:exit()

===========================================================

原文地址:https://www.cnblogs.com/zhijiangch/p/14940063.html