分享

【深度学习1】buntu22.04从零开始搭建深度学习环境_ubuntu深度学习

 netouch 2023-05-18 发布于北京

一. 安装ubuntu22.04系统

二. 安装Nvidia显卡驱动

安装之前进入主板BIOS,关闭安全启动!!!
在这里插入图片描述

  1. 更新软件列表
sudo apt-get update
  1. 安装必要的依赖
sudo apt-get install g++ 
sudo apt-get install gcc
sudo apt-get install make
  1. 根据显卡型号下载对应的驱动,官方驱动下载链接:GeForce® 驱动程序
  2. 卸载原有驱动(若有)
sudo apt-get remove --purge nvidia*
  1. 禁用nouveau驱动,在/etc/modprobe.d/blacklist.conf末尾添加
blacklist nouveau       	# prevent the kernel from loading the nouveau module at all.
options nouveau modeset=0   # if the nouveau module is built into the kernel directly, disable it.
  1. 更新初始 ram 文件系统,随后重启计算机
sudo update-initramfs –u

【注】:An initramfs is a filesystem that is embedded into the kernel and loaded at boot time. It is used to mount the real root filesystem and to provide early userspace with the necessary drivers and tools to boot the system.

  1. 停止当前显示服务器Ctrl + Alt + F1~F6,进入黑屏的文本界面,然后根据用户名和密码登录。(若后续要退出文本界面到原图形界面trl + Alt + F1/F7/F8
  2. 禁用X-window服务,根据显示管理器为gdm3lightdm选择对应命令(二选一,登录Ubuntu时输密码的登录窗口位于左边是lightdm,位于正中是gdm3)
sudo service gdm3 stop
sudo service lightdm stop
  1. cd进入存放驱动文件的目录,输入指令进行安装
sudo chmod 777 NVIDIA-Linux-xxx.run
sudo ./NVIDIA-Linux-xxx.run –no-opengl-files

可能出现的安装选项

  • 首先选择continue installation
  • register the kernel module souces with DKMS?,选择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-smi就能有如下输出了
在这里插入图片描述

三. 安装cuda

wget https://developer.download./compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run
sudo sh cuda_11.7.1_515.65.01_linux.run
  • 安装过程中,首先输入accept,取消勾选Driver(已经安装了驱动),选择Install,回车
    在这里插入图片描述
  • 安装完成后,如下所示
    在这里插入图片描述
  • 添加环境变量
export PATH=/usr/local/cuda-11.7/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH
  • 测试cuda安装
nvcc -V

输出如下,版本对应上就成功了:
在这里插入图片描述

四. 安装cudnn

tar -xvf cudnn-linux-xxx.tar.xz
  • 将解压的文件拷贝到cuda对应目录,进行cudnn的安装
sudo cp include/cudnn.h /usr/local/cuda-11.7/include
sudo cp lib/libcudnn* /usr/local/cuda-11.7/lib64
sudo chmod a+r /usr/local/cuda-11.7/include/cudnn.h /usr/local/cuda-11.7/lib64/libcudnn*

至此,GPU驱动、CUDA、cudnn就都安装好了。

五. 安装anaconda

Anaconda是一种软件包管理,它为编程语言Python和R提供图形导航,支持数据科学、数据分析和机器学习。
Anaconda让您不必担心有时遇到复杂的依赖关系问题。此外,Anaconda有一个名为Conda的包管理器,它可以使分发中的所有包保持最新。它促进了库和开发环境的安装和管理,支持在Python和R下进行数据分析和机器学习。总的来说,有许多软件包可用,包括Jupyter Notebook、Spyder、NumPy和TensorFlow。
Anaconda可用于Microsoft Windows、macOS和Linux的个人、商业、团队和企业版本。个人版是开源软件,作为免费软件免费,因此,例如,私人用户可以学习如何处理数据分析。付费版商业版、团队版和企业版为商业使用和公司使用提供了广泛的功能。

  1. 下载anaconda安装程序,可以anaconda官网或在清华大学开源软件镜像站下载anaconda。
    Anaconda官网清华大学开源软件镜像站
  2. cd进入下载到的目录中,用sh命令语言解释器运行.sh文件安装anaconda
sh Anaconda3-*.sh
  1. 一直按Enter,输入yes接受license,按Enter安装到ubuntu当前用户路径,等待unpacking payload
    在这里插入图片描述

  2. 安装程序通过conda init初始化Anaconda3,输入yes,并回车
    在这里插入图片描述

  3. 为anaconda添加环境变量

echo "export PATH=$PATH:/home/你自己的用户名/anaconda3/bin">> ~/.bashrc
  1. source ~/.bashrc或重开终端生效,开始使用Anaconda吧~

如何卸载Anaconda

  1. 完全卸载
conda install anaconda-clean
anaconda-clean --yes
  1. 标准删除
rm -rf anaconda3
rm -rf ~/anaconda3
rm -rf ~/opt/anaconda3

# 将配置文件中anaconda的PATH都移除
# 在下述两个文件中找到anacodna3行并将其删除。之后,使用Ctlr+s保存文件。
sudo nano .bashrc
sudo nano .profile

六. 安装pycharm

直接在Ubuntu Software中搜索pycharm并安装即可。
在这里插入图片描述
至此,ubuntu22.04系统基本的深度学习开发环境就搭建好了~

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多