Ubuntu20.04+PyCharm+Tensorflow+Docker环境搭建 I

目录

1、ubuntu系统安装

系统配置

引导界面美化

解决双系统时间问题

 2、Docker安装

安装docker

安装nvidia-container-toolkit

3、TensorFlow 安装


1、ubuntu系统安装

具体的安装过程参考 https://www.jb51.net/article/187767.htm

ubuntu安装准备

官网下载镜像:https://ubuntu.com/download/desktop

下载rufus(官网推荐)https://rufus.ie/

用于刻录ubuntu系统到u盘


系统配置

部分配置过程参考 https://zhuanlan.zhihu.com/p/139305626

首先把软件源切换为国内的软件源

显卡驱动安装

参考 https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-20-04-focal-fossa-linux

sougou输入法安装

参考 https://pinyin.sogou.com/linux/help.php


引导界面美化

win10 + Ubuntu 20.04 LTS 双系统 引导界面美化转载自: https://blog.csdn.net/ZChen1996/article/details/106130085/

效果展示

自带引导界面太丑,下个主题美化一下,效果如下
在这里插入图片描述

主题下载地址

此主题下载地址:https://www.gnome-look.org/p/1009236/
下载速度慢或打不开的(一般是打不开的)可以用我下载好的(只有这一个主题,别的没有):百度网盘链接:https://pan.baidu.com/s/1-mOl3_mHZZVh_PVMq9oQ1w 提取码:2pbn

安装主题

解压

$ tar xvJf Vimix-1080p.tar.xz

20200515 020226 的屏幕截图.png
进入解压后的文件夹

$ cd Vimix-1080p

安装

sudo ./install.sh

20200515 020226 的屏幕截图.png

修改启动设置,在命令行中输入

$ sudo vim /etc/default/grub

在这里插入图片描述
一般我们需要更改其中的 GRUB_DEFAULT(默认启动项:这个编号是你开机时看到的若干个启动项从上到下的依次编号,记住!编号是从0开始的,意思是,第一项是0,第二项是1,以此类推)、GRUB_TIMEOUT_STYLE(是否显示倒计时,hidden的属性表示不会显示倒计时)、GRUB_TIMEOUT(等待时间,单位是秒)
按自身需求更改后,保存即可。

更新

记住最后一定要对更改进行更新
在命令行输入

$ sudo update-grub

解决双系统时间问题

Win10 + Ubuntu20.04双系统下时间不同步问题

如果你是双系统,安装完 Ubuntu 设置好系统时间后,回到 Windows 会发现时间不统一。为了理解为什么,我们得先了解点基础知识:

  • UTC(Coordinated Universal Time),协调世界时(世界统一时间);
  • GMT(Greenwich Mean Time),格林威治标准时间。

Windows 与类 Unix 系统(Unix/Linux/Mac)看待系统硬件时间的方式是不一样的:

  • Windows 把计算机硬件时间当作本地时间(local time),所以在 Windows 系统中显示的时间跟 BIOS 中显示的时间是一样的。
  • 类 Unix 系统把计算机硬件时间当作 UTC, 所以系统启动后会在该时间的基础上,加上电脑设置的时区数(比中国就加8),因此 Ubuntu 中显示的时间总是比 Windows 中显示的时间快 8 小时。

当你在 Ubuntu 中把系统显示的时间设置正确后,计算机硬件时间就变成了在这个时间上减去 8 小时,所以当你切换成 Windows 系统后慢了8小时,就是这个原因。

解决方案:在 Ubuntu 中把计算机硬件的时间改成系统显示时间,即禁用 Ubuntu 中的 UTC

timedatectl set-local-rtc 1 --adjust-system-clock

 2、Docker安装

安装docker

参考 https://www.cnblogs.com/chengmf/p/13122013.html

配置安装环境

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

 添加阿里云的docker GPG密钥

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加阿里镜像源

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

#更新
sudo apt-get update

 查看docker版本

apt-cache madison docker-ce

安装最新版或指定版本

#安装最新版
sudo apt-get install -y docker-ce

#安装5:19.03.6~3-0~ubuntu-bionic版
sudo apt-get install -y docker-ce=5:19.03.6~3-0~ubuntu-bionic

 重启docker

sudo service docker restart
#或者
sudo systemctl restart docker

配置国内docker镜像加速

参考https://www.cnblogs.com/nhdlb/p/12567154.html

创建或修改 /etc/docker/daemon.json 文件,修改为如下形式

{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}

加载重启docker

sudo systemctl daemon-reload
sudo systemctl restart docker

查看是否成功,能查看到registry mirrors的内容表示成功

docker info

 


安装nvidia-container-toolkit

参考https://www.jianshu.com/p/878569e1a845

最新版的nvidia-docker就是nvidia-container-toolkit,比nvidia-docker2更加优秀。官方的解释是"Usage of nvidia-docker2 packages are deprecated since NVIDIA GPUs are now natively supported as devices in the Docker runtime"。(机翻:不赞成使用nvidia-docker2包,因为nvidia GPU现在在Docker运行时本机作为可支持设备)

nvidia-container-toolkit需要主机已安装当前新版的docker 19.03

使用nvidia-container-toolkit的最大优点:linux主机不需要安装cuda和cudnn,仅安装显卡驱动即可(tensorflow和nvidia-docker官方均强调这一点)

参考 https://www.lidaren.com/archives/1950

docker升级到19.03以后,nvidia将提供原生的显卡支持,只需要安装nvidia-container-toolkit工具包即可,不再像使用nvidia-docker/2那样复杂配置,而且不支持用docker-compose

首先检查显卡驱动是否安装好 参考https://blog.csdn.net/qiancaobaicheng/article/details/95096354

nvidia-smi 

若未安装好,先卸载显卡驱动

sudo apt-get remove --purge nvidia*

重新安装显卡驱动

sudo ./NVIDIA-Linux-x86_64-396.18.run -no-x-check -no-nouveau-check -no-opengl-files //只有禁用opengl这样安装才不会出现循环登陆的问题

-no-x-check:安装驱动时关闭X服务
-no-nouveau-check:安装驱动时禁用nouveau
-no-opengl-files:只安装驱动文件,不安装OpenGL文件

The distribution-provided pre-install script failed! Are you sure you want to continue? 选择 yes 继续。
Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later?  选择 No 继续。
问题没记住,选项是:install without signing
问题大概是:Nvidia's 32-bit compatibility libraries? 选择 No 继续。
Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up.  选择 Yes

添加nvidia-docker的源

repositoriesdistribution=$(. /etc/os-release;echo$ID$VERSION_ID)

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey|sudo apt-key add -

curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list

sudo tee /etc/apt/sources.list.d/nvidia-docker.lists

sudo apt-get update

安装nvidia-container-toolkit,重启docker

sudo apt-get install -y nvidia-container-toolkit

#restart docker
sudo systemctl restart docker
#使用nvidia-container-toolkit
docker run --gpus "device=1,2"

官方参考 https://tensorflow.google.cn/install/docker


3、TensorFlow 安装

参考 https://zhuanlan.zhihu.com/p/100841363

Docker 使用容器创建虚拟环境,以便将 TensorFlow 安装与系统的其余部分隔离开来。TensorFlow 程序在此虚拟环境中运行,该环境能够与其主机共享资源(访问目录、使用 GPU、连接到互联网等)。系统会针对每个版本测试 TensorFlow Docker 映像

Docker 是在 Linux 上启用 TensorFlow GPU 支持的最简单方法,因为只需在主机上安装 NVIDIA® GPU 驱动程序(无需安装 NVIDIA® CUDA® 工具包)。注意不需要安装工具包。

GPU 支持

Docker 是在 GPU 上运行 TensorFlow 的最简单方法,因为主机只需安装 NVIDIA® 驱动程序(无需安装 NVIDIA® CUDA® 工具包)。

安装 nvidia-docker 可启动支持 NVIDIA® GPU 的 Docker 容器。nvidia-docker 仅适用于 Linux,详情请参阅对应的平台支持常见问题解答

参考 https://blog.csdn.net/thanlon/article/details/107100520

Docker安装成功,开始安装TensorFlow。首先下载 TensorFlow Docker 镜像,TensorFlow 提供了很多ensorFlow Docker 镜像。官方 TensorFlow Docker 映像位于 tensorflow/tensorflow Docker Hub 代码库中:

更换docker的国内镜像源之后,使用以下命令获得TensorFlow镜像

sudo docker pull tensorflow/tensorflow:latest-gpu-jupyter  # latest release w/ GPU support and Jupyter

成功安装

sudo docker images

 

运行 TAG 是 latest-gpu-jupyter 的容器

sudo docker run -p 8888:8888 tensorflow/tensorflow:latest-gpu-jupyter

 浏览器访问127.0.0.1:8888下面的链接就可以使用 jupyter notebook:

环境配置搭建完成!

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值