搭建python虚拟环境+CUDA+cudnn安装
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 <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /tmp/cuda-installer.log
4.4 环境变量的配置
vim .bashrc

本文详细介绍了如何在Linux环境下通过conda搭建Python 3.8虚拟环境,并安装CUDA、cuDNN及PyTorch的过程。涵盖了从环境搭建到解决版本兼容性问题的全流程,特别关注于解决PyTorch与特定版本CUDA之间的兼容性问题。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



