搭建python3.8虚拟环境+CUDA 11.2+cudnn 8.1.1安装

搭建python3.8虚拟环境+CUDA 11.2+cudnn 8.1.1安装,第1张

搭建python3.8虚拟环境+CUDA 11.2+cudnn 8.1.1安装

搭建python虚拟环境+CUDA+cudnn安装
  • 1. 利用conda搭建python3.8环境
    • 搭建结束出现:
  • 2. 激活虚拟环境
  • 3. 安装需要的包
  • 4. CUDA安装
  • 5. cuDNN安装(对应版本8.1.1)

1. 利用conda搭建python3.8环境

命令 conda create -n 2021myenv python=3.8
2021myenv 为自定义的虚拟环境名称,3.8为需要的python版本号。

搭建结束出现:

To activate this environment, use conda activate 2021myenv
To deactivate an active environment, use conda deactivate

2. 激活虚拟环境

命令source activate 2021myenv
即进入虚拟环境:(2021myenv) usr@cygnus:~/python_env$ python

3. 安装需要的包

显示已经安装了什么包:pip list
Successfully installed numpy-1.21.4
Successfully installed joblib-1.1.0

pip install -U git+git://github.com/hypergravity/laspec
Successfully installed laspec-2021.1114.0
Successfully installed torch-1.10.0 typing-extensions-4.0.0
Successfully installed absl-py-1.0.0 astunparse-1.6.3 cachetools-4.2.4 charset-normalizer-2.0.7 flatbuffers-2.0 gast-0.4.0 google-auth-2.3.3 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.41.1 h5py-3.5.0 idna-3.3 keras-2.7.0 keras-preprocessing-1.1.2 libclang-12.0.0 markdown-3.3.4 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.19.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.16.0 tensorboard-2.7.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.7.0 tensorflow-estimator-2.7.0 tensorflow-io-gcs-filesystem-0.22.0 termcolor-1.1.0 urllib3-1.26.7 werkzeug-2.0.2 wrapt-1.13.3

Successfully installed scikit-learn-1.0.1 scipy-1.7.2 sklearn-0.0 threadpoolctl-3.0.0

4. CUDA安装

4.1. cat /proc/version (Linux查看当前 *** 作系统版本信息)

4.2. cuda 11.2.0下载网址:
https://developer.nvidia.com/cuda-11.2.0-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal

notes: 按照网页的提示信息进行安装。

# 先对安装包《cuda_10.0.130_410.48_linux.run》的属性进行修改为可执行;

chmod 755  cuda_11.2.0_460.27.04_linux.run 

# 不要使用 sudo 进行安装
sh cuda_11.2.0_460.27.04_linux.run

4.3. 注意跳入options进行路径设置。

安装结束提示信息如下:

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /home/liujunhui/cuda_11_2/
Samples:  Not Selected

Please make sure that
 -   PATH includes /home/liujunhui/cuda_11_2/bin
 -   LD_LIBRARY_PATH includes /home/liujunhui/cuda_11_2/lib64, or, add /home/liujunhui/cuda_11_2/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /home/liujunhui/cuda_11_2/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 460.00 is required for CUDA 11.2 functionality to work.
To install the driver using this installer, run the following command, replacing  with the name of this run file:
    sudo .run --silent --driver

Logfile is /tmp/cuda-installer.log

4.4 环境变量的配置

vim .bashrc

# 在最下方添加刚刚安装cuda的路径:
---
export PATH="/home/liujunhui/NN_install_cuda_11_2_toolkit/bin:$PATH"
export LD_LIBRARY_PATH="/home/liujunhui/NN_install_cuda_11_2_toolkit/lib64:$LD_LIBRARY_PATH"
---

# 保存之后,使配置生效:  
source .bashrc   


命令行输入 nvcc -V 查看cuda版本,效果如下:

liujunhui@cygnus:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0
5. cuDNN安装(对应版本8.1.1)

5.1 下载

5.2 其实下载了deb文件(图上的文件没有资源)
解压 *** 作

5.3 3 安装配置【替换即可】

 cp /home/liujunhui/libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64/data/usr/include/x86_64-linux-gnu/cudnn*.h /home/liujunhui/NN_install_cuda_11_2_toolkit/include/

 cp /home/liujunhui/libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64/data/usr/lib/x86_64-linux-gnu/libcudnn.s* /home/liujunhui/NN_install_cuda_11_2_toolkit/include/lib

 chmod 755 ~/cudnn*.h
 
# 查看cudnn版本 
 cat /home/liujunhui/NN_install_cuda_11_2_toolkit/include/cudnn_version_v8.h | grep CUDNN_MAJOR -A 2

结果如下:

liujunhui@cygnus:~$ cat /home/liujunhui/NN_install_cuda_11_2_toolkit/include/cudnn_version_v8.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 1
#define CUDNN_PATCHLEVEL 1
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

#endif 

参考链接:https://www.pianshen.com/article/99731665661/

https://positive.blog.csdn.net/article/details/118080925

pytorch https://pytorch.org/get-started/cloud-partners/

其他:
查看torch支持的cuda版本:
进入python torch.version torch.version.cuda

所有Cuba下载链接:
https://developer.nvidia.com/cuda-toolkit-archive

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5521485.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存