1 虚拟环境安装
1.安装anaconda
https://mirrors.tuna./anaconda/archive/
2.进入anaconda prompt
conda config --show channels
conda config --add channels https://mirrors.tuna./anaconda/pkgs/free/conda config --add channels https://mirrors.tuna./anaconda/cloud/conda-forgeconda config --add channels https://mirrors.tuna./anaconda/cloud/msys2/
#如果想删掉conda config --remove channels https://mirrors.tuna./anaconda/pkgs/free/conda config --remove channels https://mirrors.tuna./anaconda/cloud/conda-forgeconda config --remove channels https://mirrors.tuna./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 /simple
pip install keras-i /simple #报错Cannot unpack file后改为下面一行可正常运行pip install keras -i /simple --trusted-host
python #进入python
#测试是否安装成功#导入keras时使用如下代码,在 tensorflow2.X 中导入keras模块代码使用下述方法会报错from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmaxfrom keras.models import Model#解决办法:将上述py文件中代码修改为:from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmaxfrom tensorflow.keras.models import Model#ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 这个类型报错的问题我遇到的都可以通过导入包时使用tensorflow.keras解决#该报错解决方案的原文链接:/qq_29304033/article/details/117258910
conda install nb_conda #这一句一直报错,感觉是和之前conda镜像怎么都设置不好有关#暂未解决,但不知道为什么jupyter notebook不进入虚拟环境也莫名可以使用tensorflow.keras#xs 不知道为什么根本就没装到虚拟环境里去,直接装在base环境里了,把虚拟环境文件夹删了…就先这样吧
所以整理一个不在虚拟环境里搭建keras的方法:
2 直接安装
1.下载anaconda
https://mirrors.tuna./anaconda/archive/
2.进入anaconda prompt
#安装后端tensorflowpip install tensorflow==2.0 -i /simple#安装前端keraspip install keras -i /simple --trusted-host
python #进入python
#测试是否安装成功#导入keras时使用如下代码,在 tensorflow2.X 中导入keras模块代码使用下述方法会报错from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmaxfrom keras.models import Model#解决办法:将上述py文件中代码修改为:from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmaxfrom tensorflow.keras.models import Model#ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 这个类型报错的问题我遇到的都可以通过导入包时使用tensorflow.keras解决#该报错解决方案的原文链接:/qq_29304033/article/details/117258910
如果觉得《keras环境搭建 [过程记录]》对你有帮助,请点赞、收藏,并留下你的观点哦!