您现在的位置是:首页 >技术杂谈 >ubuntu 3060显卡驱动+cuda+cudnn+pytorch+pycharm+vscode网站首页技术杂谈
ubuntu 3060显卡驱动+cuda+cudnn+pytorch+pycharm+vscode
文章目录
运行环境:
ubuntu18.04.6 melodic
宏基暗影骑士笔记本
适用:
ubuntu18.04 / ubuntu20.04
思路:
3060显卡+CUDA11.1+cudnn8.1.1+pytorch1.8.0+pycharm2021+Anaconda+vscode
1.1 3060显卡驱动自动安装
1)换清华源
2)安装nvidia-driver-470-server
3)重启电脑
4)nvidia-smi (检查已显卡驱动版本)
CUDA Version: 11.4 (显卡驱动API 11.4)
2.1 CUDA11.1.1
CUDA下载地址:https://developer.nvidia.com/cuda-toolkit-archive
1)下载CUDA Toolkit 11.1 Update 1 Downloads
(运行API,小于等于上面显卡驱动API 11.4就可以)
复制到浏览器下载, 不需要墙(30分钟)
https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run
cd 到下载路径
sudo sh cuda_11.1.1_455.32.00_linux.run
2)contunue , 然后accept
3)回车取消Driver安装,然后install
4)添加环境变量
gedit ~/.bashrc
在文件结尾添加如下语句:(修改成自己的路径)
export PATH="/usr/local/cuda-11.1/bin:$PATH"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.1/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-11.1/lib
source ~/.bashrc
nvcc -V
只要驱动API高于运行时API就没关系
nvidia-smi显示的是驱动API,nvcc -V显示的是运行时API
5)确认是否安装成功
进入deviceQuery/目录
cd usr/local/cuda-11.1/samples/1_Utilities/deviceQuery/
sudo make
执行检查版本
./deviceQuery
3.1 cudnn 8.1.1
https://developer.nvidia.com/rdp/cudnn-archive
密码:首位设置是大写
1)下载版本
Download cuDNN v8.1.1 (Feburary 26th, 2021), for CUDA 11.0,11.1 and 11.2
2)解压
tar -xvzf cudnn-11.4-linux-x64-v8.2.2.26.tgz
将解压后的文件拷贝到CUDA对应的安装目录下:(注意自己的路径)
sudo cp /home/duduzai/下载/cudnn-11.2-linux-x64-v8.1.1.33/cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp /home/duduzai/下载/cudnn-11.2-linux-x64-v8.1.1.33/cuda/lib64/libcudnn* /usr/local/cuda/lib64/
3)设置拷贝文件权限
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
4)查看cudnn版本
ls /usr/local/cuda/include/cudnn.h
如果输出 No such file or directory,则cuDNN头文件未安装或者安装位置不正确,
如果输出 /usr/local/cuda/include/cudnn.h,则cuDNN头文件已经安装成功。
ls /usr/local/cuda/lib64/libcudnn*
4.1 pycharm2021.3
1)社区版(免费)
https://www.jetbrains.com/pycharm/download/other.html
2)安装并创建pycharm图标
cd /home/duduzai/pycharm2021/bin
bash pycharm.sh
cd /usr/share/applications
sudo gedit pycharm.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Pycharm
Icon=/home/duduzai/pycharm2021/bin/pycharm.png
Exec=sh /home/duduzai/pycharm2021/bin/pycharm.sh
MimeType=application/x-py;
Name[en_US]=pycharm
5.1 Anaconda
1)下载
https://www.anaconda.com/download/
2)安装
bash Anaconda3-2023.03-Linux-x86_64.sh
一直回车
3)添加环境变量
echo 'export PATH="/home/lc/anaconda3/bin/:$PATH"' >> ~/.bashrc
gedit ~/.bashrc
source ~/.bashrc
5.2 Anaconda 环境创建
1)创建名为 lidar_camera 的环境
conda create --name lidar_camera python=3.8
2)激活环境
conda activate lidar_camera
3)显示环境的安装包
conda list
4)查看所有环境
conda env list
6.1 pytorch1.8
https://pytorch.org/get-started/previous-versions/
conda activate lidar_camera
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
7.1 Anaconda和vscode联合使用
1)安装vscode环境
2)设置conda路径
查看conda环境路径
/home/duduzai/anaconda3/envs/lidar_camera/bin/python