1.安装anaconda
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
2.进入anaconda prompt
conda config --show channels
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
#如果想删掉 conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ #但是上面那种方法会把channels变成空的[],所以我们还是选择换回默认源更好 conda config --remove-key channels #查看当前使用源 conda config --show-sources #ssl_verify: True #show_channel_urls: True
conda create -n keras #创建虚拟环境
conda activate keras #进入虚拟环境
pip install tensorflow==2.0 -i https://pypi.doubanio.com/simple
pip install keras-i https://pypi.doubanio.com/simple #报错Cannot unpack file后改为下面一行可正常运行 pip install keras -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com
python #进入python
#测试是否安装成功 #导入keras时使用如下代码,在 tensorflow2.X 中导入keras模块代码使用下述方法会报错 from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from keras.models import Model #解决办法:将上述py文件中代码修改为: from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from tensorflow.keras.models import Model #importError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 这个类型报错的问题我遇到的都可以通过导入包时使用tensorflow.keras解决 #该报错解决方案的原文链接:https://blog.csdn.net/qq_29304033/article/details/117258910
conda install nb_conda #这一句一直报错,感觉是和之前conda镜像怎么都设置不好有关 #暂未解决,但不知道为什么jupyter notebook不进入虚拟环境也莫名可以使用tensorflow.keras #xs 不知道为什么根本就没装到虚拟环境里去,直接装在base环境里了,把虚拟环境文件夹删了…就先这样吧
所以整理一个不在虚拟环境里搭建keras的方法:
2 直接安装1.下载anaconda
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
2.进入anaconda prompt
#安装后端tensorflow pip install tensorflow==2.0 -i https://pypi.doubanio.com/simple #安装前端keras pip install keras -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com
python #进入python
#测试是否安装成功 #导入keras时使用如下代码,在 tensorflow2.X 中导入keras模块代码使用下述方法会报错 from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from keras.models import Model #解决办法:将上述py文件中代码修改为: from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from tensorflow.keras.models import Model #importError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 这个类型报错的问题我遇到的都可以通过导入包时使用tensorflow.keras解决 #该报错解决方案的原文链接:https://blog.csdn.net/qq_29304033/article/details/117258910


![keras环境搭建 [过程记录] keras环境搭建 [过程记录]](http://www.mshxw.com/aiimages/31/445067.png)
