安装Keras,tensorflow,并实现将虚拟环境添加到jupyter notebook,


目录
  • 写在面前
  • 安装全过程
  • 接下来往虚拟环境装tensorflow和keras
  • 总结

写在面前

最近需要用LSTM,今天开始搭环境,遇到了很多问题,其中主要是两个问题

不太懂装环境的朋友可以注意一下:

1、tensorflow和keras以及numpy等等版本的兼容问题。一般的keras安装教程tensorflow和keras版本都是兼容的,但是自己还得去装numpy,一不小心版本就不兼容了,所以我的每一步安装都规定了版本,防止不兼容问题;

2、因为用不惯pycharm,所以keras安装好了我想用jupyter打开,结果遇到了各种问题。例如无法识别jupyter notebook这个命令等等。所以我索性改变思路,先把虚拟环境加入到jupyter中,然后再在虚拟环境里面装包。

安装全过程

都是用的清华园镜像,网速好两三分钟就能全部装好!

  • 第一步:创建虚拟环境(tf3是我的虚拟环境的名称,你可以自己取)
conda create -n tf3 python=3.6.5   
  • 第二步:安装 ipykernel
pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第三步:把新建的虚拟环境(tf3)加入到jupter notebook里面
python -m ipykernel install --name tf3

截至这里,虚拟环境就加入到jupter notebook里面了

接下来往虚拟环境装tensorflow和keras

  • 第一步:首先要进入到新建的虚拟环境
conda activate tf3
  • 第二步:安装tensorflow
pip install tensorflow==2.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第三步:安装keras
pip install keras==2.4.3 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第四步:安装numpy
pip install numpy==1.19.5 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第五步:安装pandas
pip install pandas==1.1.4 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第六步:安装scikit-learn 
pip install scikit-learn==0.24.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第七步:安装scipy
pip install scipy==1.5.4 -i https://pypi.tuna.tsinghua.edu.cn/simple/
  • 第八步:安装matplotlib
pip install matplotlib==3.3.3 -i https://pypi.tuna.tsinghua.edu.cn/simple/

最后在jupyter notebook里面引入相关库,没报错就说明ok了

from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持3672js教程。

您可能感兴趣的文章:
  • 关于TensorFlow、Keras、Python版本匹配一览表
  • 亲测解决tensorflow和keras版本不匹配的问题
  • tensorflow1.15与numpy、keras以及Python兼容版本对照方式
  • 关于tensorflow中tf.keras.models.Sequential()的用法
  • 解决安装和导入tensorflow、keras出错的问题
  • 关于Tensorflow和Keras版本对照及环境安装

评论关闭