工欲善其事,必先利其器
工欲善其事,必先利其器是说:工匠想要使他的工作做好,一定要先让工具锋利。比喻要做好一件事,准备工作非常重要。语出《论语·卫灵公》:子贡问为仁。子曰:“工欲善其事,必先利其器。居是邦也,事其大夫之贤者,友其士之仁者。”
An artisan must first sharpen his tools if he is to do his work well.
全文涉及软件下载 Google Drive
目录
conda经常由于网速问题, 在安装一些比较大的包时会卡住而失败. 例如报错: (熟悉吧)
CondaError: CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://conda.anaconda.org/menpo/linux-64/boost-1.59.0-py27_0.tar.bz2
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
cuda/ cudnn
Download
1、官网下载准备安装包:
- cuda :选择对应的系统 --> runfile(local) --> Base Installer + Patch 1(补丁)
- cudnn :注册登录–>选择对应版本–>Runtime Library + Developer Library + Code Samples 三个文件下载(Linux 版本)
2、命令行下载 (cuda):
wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run
Install & Uninstall
***cuda***
!!!安装
sudo sh ./cuda_***_linux.run
或者
sudo chmod +x ./cuda_***_linux.run (加入可执行权限)
sudo ./cuda_***_linux.run
!!卸载
sudo /usr/local/cuda/bin/uninstall*** #不同版本,卸载文件名不一样,但都是执行该类文件即可
!!!查看
nvcc -V
或者
nvidia-smi
!!!添加PATH
#文件路径,看着改就行
vim ~/.bashrc
export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
source ~/.bashrc
***cudnn***
!!!安装
sudo dpkg -i libcudnn8_8.0.3.33-1+cuda11.0_amd64.deb
sudo dpkg -i libcudnn8-dev_8.0.3.33-1+cuda11.0_amd64.deb
sudo dpkg -i libcudnn8-samples_8.0.3.33-1+cuda11.0_amd64.deb
!!!卸载
sudo rm -rf /usr/local/cuda/include/cudnn.h
sudo rm -rf /usr/local/cuda/lib64/libcudnn*
#可选操作,删了会更干净点,没有找到就算了,问题不大
whereis libcudnn.so.8 (不同版本数字不一样)
rm -f libcudnn.so.8
!!!查看
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
如果出现如下信息,说明cuDNN已正确识别。版本为7.6.5
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6
#define CUDNN_PATCHLEVEL 5
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"
anaconda
Download
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh(文件下载的URL)
Install & Uninstall
!!!安装
bash ./Anaconda***.sh --> 根据提示修改路径(默认或自定义)
!!!卸载
删除安装位置的Anaconda文件即可
!!!添加PATH
vim ~/.bashrc
export PATH=/anaconda_path/bin:$PATH
export LD_LIBRARY_PATH=/anaconda_path/bin:$LD_LIBRARY_PATH
!!!查看
$ python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 8 2020, 23:10:56) │
[GCC 7.3.0] on linux │
Type "help", "copyright", "credits" or "license" for more information.
!!!创建一个新环境
conda create -n new_env python=3.X
source activate new_env
source/conda deactivate new_env
pytorch / torchvision / cudatoolkit
要想用conda快速的创建新的开发环境,并安装所需要的第三方包,最为常规的做法就是加入各种各样的国内镜像channels,但可能还会是出现下面的情况:
CondaError: CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://conda.anaconda.org/menpo/linux-64/boost-1.59.0-py27_0.tar.bz2
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
现在该怎么办?没办法了吗?有的!请往下看:
pytorch 官网安装指令
# CUDA 10.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch
- 常规方法
# 添加清华镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://pypi.tuna.tsinghua.edu.cn/simple/
#添加中科大镜像
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
#查看已经添加的channels
conda config --get channels
- 本文方法
1、先看官网安装指令,找到pytorch、torchvision、cudatoolkit对应的版本,或者看我的博客。
2、下载 .whl 轮子文件 或者 .whl 下载 torch 和 torchvision,然后用 pip 进行安装。
pip install torch-1.1.0-cp36-cp36m-linux_x86_64.whl
pip install torchvision-0.3.0-cp36-cp36m-linux_x86_64.whl
3、到清华镜像网站,下载cudatoolkit文件。(Tips:在用conda安装文件的时候,如果设置了显示安装 –set show_channel_urls yes 就可以知道每一个包到底是在哪里下载的,所以失败了,就手动去对应的网址下载!然后,Ctrl + F 输入cuda就会定位到cudatoolkit那一列)
conda install --offline ./cudnn-7.0.5-cuda8.0_0.tar.bz2 或者 .conda
版本检测
# cuda
nvcc -V
nvidia-smi
cat /usr/local/cuda/version.txt
#cudnn
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#python
python
#pytorch & torchvision
import torch
import torchversion
torch.__version__
torchvision.__version
torch.version.cuda
torch.cuda.is_available()
torch.cuda.device_count()
torch.cuda.current_device()