【linux】【深度学习】从零开始在linux机器上面搭建pyTorch环境

【零】

查看linux系统版本

cat /etc/issue : ubuntu

查看cuda版本:

cat /usr/local/cuda/version.txt 需要找到安装cuda的路径

nvcc -V 需要安装 nvidia-cuda-toolkit 包。。。

nvidia-smi

【一】安装miniconda

wget -c https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

bash Miniconda3-latest-Linux-x86_64.sh

看license / 确定安装路径 / ... 一路yes (风险:可能破坏当前环境)

【二】miniconda设置

镜像源

conda config --show channels

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 --show-sources

新建虚拟环境

conda create -n ENVNAME python=3.7

conda create -n ENVNAME --clone base

默认不激活

conda config --set auto_activate_base false

激活某个环境

conda activate ENVNAME

退出某个环境

deactivate

【三】安装乱七八糟包

conda install pyarrow=0.13.0

conda install tornado

conda install scikit-learn

在安装torch / torchvision 的时候,如果用pip从原始镜像,就会很慢,如果用conda加上-c pytorch,可以使用清华镜像,但是是cpu版本,但是如果conda,不用清华镜像还是很慢。

所以先从官网上下载下torch / torchvision的whl文件,然后用pip安装一下。 先torch后torchvision。pip install xxx.whl

pip install botorch

pip install tensorboardX

pip install -U ray

conda install -c conda-forge optuna

另外需要的包 jsonrpcserver / jsonrpcclient / arctic / requests / ipython

【测试】

import torch

torch.cuda.is_available()

torch.cuda.device_count()

【奇怪的问题】

命令行只有一个美元符号而没有路径:可以直接在命令行输入bash解决,如果不想每次都输入一遍,可以参照文章 https://blog.csdn.net/weixin_34409822/article/details/85616519