Ubuntu 22.04LTS + 深度学习环境安装全流程

部署运行你感兴趣的模型镜像

一、 CUDA Toolkit 安装

1. 选择需要安装的版本(下载地址)

在这里插入图片描述

2. 选择自己的系统版本获取下载地址和安装指令

3. 运行安装指令进行安装

wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run
sudo sh cuda_12.2.2_535.104.05_linux.run

选择安装选项:
在这里插入图片描述
这里安装显卡驱动比较麻烦,所以这一步按空格或者Enter键去掉安装显卡驱动的选项,然后选择install
在这里插入图片描述

安装正常:
在这里插入图片描述

配置环境变量:

vim ~/.bashrc

# 添加一行
export PATH=/usr/local/cuda-12.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# 保存并加载环境变量
source ~/.bashrc

验证安装是否成功:

root@service2:~# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Aug_15_22:02:13_PDT_2023
Cuda compilation tools, release 12.2, V12.2.140
Build cuda_12.2.r12.2/compiler.33191640_0

4. 可能出现测错误

gcc未安装或版本不对:

报错 :

	cat /var/log/cuda-installer.log
	
	[INFO]: Driver not installed.
	[INFO]: Checking compiler version...
	[INFO]: gcc location: G 
	[ERROR]: Missing gcc. gcc is required to continue.

解决方法 :

	# 确保 GCC 已经安装:
	gcc --version
	
	# 如果输出显示 GCC 版本信息,则说明已经安装。
	
	# 如果没有安装,请执行以下命令安装 GCC:
	sudo apt update
	sudo apt install gcc
	
驱动不兼容

报错:

cat /var/log/nvidia-installer.log
ERROR: The Nouveau kernel driver is currently in use by your system.  This driver is incompatible with the NVIDIA driver, and must be disabled before proceeding.  Please consult the NVIDIA driver README and your Linux distribution's documentation for details on how to correctly disable the Nouveau kernel driver.
-> For some distributions, Nouveau can be disabled by adding a file in the modprobe configuration directory.  Would you like nvidia-installer to attempt to create this modprobe file for you? (Answer: Yes)
-> One or more modprobe configuration files to disable Nouveau have been written.  For some distributions, this may be sufficient to disable Nouveau; other distributions may require modification of the initial ramdisk.  Please reboot your system and attempt NVIDIA driver installation again.  Note if you later wish to re-enable Nouveau, you will need to delete these files: /usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf, /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

解决方式


echo "blacklist nouveau" >> /lib/modprobe.d/dist-blacklist.conf
echo "options nouveau modeset=0" >> /lib/modprobe.d/dist-blacklist.conf
 
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r) 
systemctl set-default multi-user.target 
reboot

1.2 显卡驱动安装(需要重启)

自动安装显卡驱动:

sudo ubuntu-drivers autoinstall

检验驱动是否安装成功: nvidia-smi
在这里插入图片描述
如果有下面报错:

root@service5:/home/voke# sudo ubuntu-drivers autoinstall
Traceback (most recent call last):
  File "/usr/bin/ubuntu-drivers", line 513, in <module>
    greet()
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/bin/ubuntu-drivers", line 432, in autoinstall
    command_install(config)
  File "/usr/bin/ubuntu-drivers", line 187, in command_install
    UbuntuDrivers.detect.nvidia_desktop_pre_installation_hook(to_install)
  File "/usr/lib/python3/dist-packages/UbuntuDrivers/detect.py", line 839, in nvidia_desktop_pre_installation_hook
    with_nvidia_kms = version >= 470
UnboundLocalError: local variable 'version' referenced before assignment

查询可安装的驱动:

# 更新包管理
sudo apt update
sudo apt upgrade

# 更新 ubuntu-drivers 工具
sudo apt install --reinstall ubuntu-drivers-common

# 手动安装 NVIDIA 驱动
ubuntu-drivers list
sudo apt install 上面显示的驱动程序名称

# ***-server 服务器版本
# ****-open 开源版本

二、安装 cuDNN

访问官网,获取下载地址(需要开发者账号)
在这里插入图片描述
下载并安装

# 登录并下载文件后,上传到服务器, 再进行安装
apt install ./cudnn-local-repo-ubuntu2204-8.9.3.28_1.0-1_amd64.deb

三、安装Mincanda

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh

运行系统环境变量初始化命令:

~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
source ~/.bashrc
3.1 更换清华源镜像

各系统都可以通过修改用户目录下的 .condarc 文件来使用 TUNA 镜像源

conda config --set show_channel_urls yes
vim ~/.condarc

编辑入如下内容:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

3.2pip设置清华源

创建或编辑pip配置文件:

如果没有~/.pip目录,首先创建它:

mkdir -p ~/.pip

接下来,创建或编辑~/.pip/pip.conf文件。您可以使用任何文本编辑器,比如nano或vim。

vim ~/.pip/pip.conf

在编辑器中,将以下内容添加到pip.conf文件中,以将pip源设置为清华大学镜像:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

验证更改:

pip config get global.index-url

这将显示全局pip源的URL,应该显示清华源的URL。

四、安装PyTorch

选择系统版本获取下载命令
在这里插入图片描述
直接安装最新版即可

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

出现如下内容表示成功

Preparing transaction: done                                              
Verifying transaction: done                                              
Executing transaction: done   

验证安装是否成功:

执行 python

# 验证torch安装
import torch
print(torch.__version__)

#验证cuda安装
print(torch.cuda.is_available())

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

<think>好的,我现在需要帮助用户查找三星A50设备在Android 10版本上的构建指纹和发布密钥信息。首先,我需要明确用户的需求是什么。构建指纹(build fingerprint)和发布密钥(release keys)通常用于设备识别和软件验证,可能用户在进行系统开发、刷机或验证设备合法性时需要这些信息。 接下来,我应该考虑从哪里获取这些信息。构建指纹通常可以在设备的设置中找到,或者通过ADB命令提取。发布密钥可能涉及更底层的系统信息,可能需要访问官方发布的源代码或相关文档。不过,用户可能没有设备在手,或者希望直接获取官方提供的数据,因此需要提供官方来源或可靠的方法。 首先,构建指纹的格式一般是这样的:$(品牌)/(设备型号)/(型号代号):$(Android版本)/$(构建ID)/$(构建版本号):$(类型)/$(标签)/$(发布密钥标识符)$。例如,三星设备的构建指纹可能类似于“samsung/a50qnsxx/a50q:10/QP1A.190711.020/A505FDDS9CUD1:user/release-keys”。用户需要确认具体的型号和版本,因为三星A50可能有多个变体,比如A505F、A505GN等,不同型号的构建指纹可能不同。 要获取构建指纹,用户可以通过以下步骤: 1. 在设备上进入“设置” > “关于手机” > “软件信息”,查找“构建编号”或类似条目。 2. 使用ADB命令:连接设备到电脑,启用USB调试后,执行`adb shell getprop ro.build.fingerprint`。这会直接输出构建指纹。 关于发布密钥(release keys),这些信息通常包含在设备的系统镜像或官方固件中。三星的官方固件可以在官方网站如SamMobile或通过官方工具如Smart Switch找到。发布密钥可能与构建指纹中的“release-keys”标签相关,表示设备使用的是正式版密钥签名,而非测试版(如dev-keys或test-keys)。 此外,Android开源项目(AOSP)的源代码中可能包含部分信息,但三星的专有部分可能不会公开。因此,最可靠的方式是直接从设备提取或参考三星官方发布的文档。 用户可能需要这些信息来进行ROM验证、开发自定义ROM或解决兼容性问题。需要注意的是,直接分享构建指纹和发布密钥可能存在安全风险,因为这些信息可能被用于伪造设备标识。因此,建议用户仅从官方渠道获取,并确保信息的安全性。 如果用户无法访问设备,可以建议他们查阅三星的官方支持页面,或通过固件下载网站查找对应型号和区域的固件详情,其中可能包含构建指纹。例如,访问SamMobile(https://www.sammobile.com/),搜索A50的Android 10固件,下载页面通常会列出详细的构建信息,包括版本号、构建日期等,从而推断出构建指纹的结构。 总结步骤: 1. 使用设备设置或ADB命令获取构建指纹。 2. 通过官方固件渠道查找发布密钥相关信息。 3. 注意设备型号和区域的差异,确保信息准确。</think>要获取三星Galaxy A50(Android 10)的构建指纹(build fingerprint)和发布密钥(release keys),可通过以下方法: 1. **构建指纹提取** 在设备上执行以下操作: - **通过系统设置**: 进入`设置 > 关于手机 > 软件信息 > 版本号`,连续点击版本号激活开发者模式,返回后查看`编译编号`或`基带版本`。 - **通过ADB命令**: 连接设备至电脑并启用USB调试,执行: ```bash adb shell getprop ro.build.fingerprint ``` 典型输出示例: $$samsung/a50qnsxx/a50q:10/QP1A.190711.020/A505FDDS9CUD1:user/release-keys$$ 2. **发布密钥信息** 发布密钥用于系统镜像签名,通常与`release-keys`标签关联。三星官方固件可通过以下渠道验证: - **官方固件下载平台**:如[SamMobile](https://www.sammobile.com/)或[Frija工具](https://forum.xda-developers.com/t/tool-frija-samsung-firmware-downloader-checker.3910594/),搜索型号`SM-A505F`(国际版)等变体,下载页面会包含构建版本号和安全补丁日期[^1]。 - **设备`/system/build.prop`文件**:通过Root权限或ADB提取: ```bash adb pull /system/build.prop ``` 3. **注意事项** - 不同地区/运营商型号(如`SM-A505F`、`SM-A505GN`)的构建指纹可能不同。 - `release-keys`表明系统为官方签名版本,与测试版(`dev-keys`或`test-keys`)区分[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐大帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值