深度学习环境配置:Windows安装TensorFlow并在Jupyter notebook上使用

前言

深度学习环境配置:Windows安装TensorFlow并在Jupyter notebook上使用

01. 安装Anaconda

  • 官网下载地址:https://www.anaconda.com/products/individual

  • 清华大学镜像源地址(推荐使用国内源镜像):https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D

  • 根据个人需求下载对应的版本。如果在官网下载,因为python2.x官方已经停止更新,建议下载bpython3.X对应的版本。如果在清华地址下载,下载最新的版本即可。

## 1.1 国内镜像源配置

  1. 清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pbkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  1. 中科大镜像源(小编选择这个)
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  1. 切回默认源
    注意,如果切换镜像后当出现下载不了的情况,就先切换默认源,然后再修改另一个可以使用的conda源(一定要先恢复默认,再换另一个!!!),也可以使用其他镜像网站
conda config --remove-key channels
  1. 查看当前用的源
conda config --show channels 

## 1.2 为tensorflow创建虚拟环境例子:本来想用这样的配置方式,但是jupyter一直连接不上,pycharm、ipython却没有问题。

  • 推荐阅读tensorflow官方教程
conda create -n tf1.15 python=3.6
  • 激活TensorFlow环境
conda activate tf1.15
  • 在虚拟环境中安装tensorflow
conda/pip install tensorflow==2.6.0
conda/pip install tensorflow-gpu==2.6.0 
conda/pip install --upgrade tensorflow #会更新到2.x
# conda install ipykernel
# conda install jupyter
conda install jupyter notebook
  • 安装特定虚拟环境的内核

python -m ipykernel install --user --name myenv --display-name "myenv"
python -m ipykernel install --user --name tf1.15 --display-name "tf1.15"
ipython kernel install --user --name tf1.15 --display-name tf1.15

ipython kernel install --user --name kr243 --display-name kr243 

ipython kernel install --user --name tensorflow --display-name tensorflow 
ipython kernelspec install-self --user

jupyter kernelspec install-self --user 

# 查看内核安装位置
# jupyter kernelspec list
  • 删除虚拟环境
conda remove -n tensorflow --all

# 02. 安装tensorflow

  • 上述的## 1.2 为tensorflow创建虚拟环境例子配置完成后,jupyter不能完美工作,于是有了这部分。
  • 此处推荐参考文章:深度学习环境配置:tensorflow-gpu + keras,和参考视频https://www.bilibili.com/video/BV1HV411q7xD,很好的阐释了各版本如何匹配选择。
  • 小编使用的是Python 3.9.7,所以需要选择tensorflow-2.6.0,选择对照表如下:
  • 深度学习环境配置:Windows安装TensorFlow并在Jupyter notebook上使用_第1张图片
  • 打开命令提示符进行下面安装,注意,小编用的就是这个,而没有选择虚拟环境在这里插入图片描述
pip install tensorflow==2.6.0
pip install tensorflow-gpu==2.6.0

# 03. 配置jupyter notebook默认工作目录

  • 修改Jupyter Notebook的默认工作目录

其他参考文章:

  • Python环境配置保姆教程(Anaconda、Jupyter、GPU环境)!:内容残缺,就比如jupyter notebook这部分配置,修改快捷方式就没有提到,导致小编失败;

  • Tensorflow安装教程 傻瓜式一键安装:

  • jupyter notebook上完美运行tensorflow、keras

  • Win10下用Anaconda安装TensorFlow

  • 手把手装anaconda下安装TensorFlow2.3(Python3.8)

  • Anaconda环境安装tensorflow并嵌入到jupyter notebook中

  • Windows环境下安装TensorFlow并在Jupyter notebook上使用

  • 可能会遇到的报错
    Could not load dynamic library ‘cudart64_110.dll‘; dlerror: cudart64_110.dll not found
    jupyter notebook在运行时后台报错 KernelRestarter: restart failed
    anaconda下tensorflow安装遇到的问题记录及解决办法
    解决Jupyter连接不上Kernel(内核)的问题

后记

  • 肯定不是完美的教程,此处记录,只是为了自己后期查阅。

你可能感兴趣的:(Python,tensorflow,深度学习,windows)