-
首先使用root权限创建环境:
sudo -s
conda create-n 你的虚拟环境名 python=3.7
-
查询与自己安装的cuda对应的版本,由于直接在线安装较慢,有以下两种较快的方法:
强烈推荐方法二,亲测好用
1)方法一:可以先将torch-1.3.0和torchvision-0.4.1的.whl文件下载好,下载地址:
https://download.pytorch.org/whl/torch_stable.html
激活刚刚创建的环境,比如这里我的是:
source activate pytorch
进入环境后使用pip命令离线安装torch和torchvision:
a. 进入下载目录,并安装torch:
pip3 install torch-1.0.0-cp37-cp37m-linux_x86_64.whl
(pytorch) root@yy:~# cd '/home/yy/下载' (pytorch) root@yy:~/下载# ls Anaconda3-2020.02-Linux-x86_64.sh cudnn-10.0-linux-x64-v7.4.2.24.tgz cuda torch-1.0.0-cp37-cp37m-linux_x86_64.whl cuda_10.0.130_410.48_linux.run (pytorch) root@yy:~/下载# pip3 install torch-1.0.0-cp37-cp37m-linux_x86_64.whl WARNING: The directory '/home/yy/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Processing ./torch-1.0.0-cp37-cp37m-linux_x86_64.whl Installing collected packages: torch Successfully installed torch-1.0.0
注:如果出现如下Requirement already satisfied
Requirement already satisfied: pillow>=4.1.1 in /home/yy/anaconda3/envs/pytorch/lib/python3.7/site-packages (from torchvision==0.3.0) (7.2.0) Requirement already satisfied: six in /home/yy/anaconda3/envs/pytorch/lib/python3.7/site-packages (from torchvision==0.3.0) (1.15.0)
可以使用 pip3 install --target=目标路径 工具包名字 指定安装路径来解决:
pip3 install --target=/home/yy/anaconda3/envs/pytorch/lib/python3.7/site-packages torchvision-0.3.0-cp37-cp37m-linux_x86_64.whl
2)方法二:使用清华源下载pytorch,快速离线安装进入
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
Ctrl+F输入pytorch,找到对应的版本并右键复制连接,打开终端使用wget命令下载
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2
下载结果如下,存放在主目录中(pytorch) root@yy:~# wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2 --2020-08-17 12:03:59-- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2 正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度: 361340025 (345M) [application/octet-stream] 正在保存至: “pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2” pytorch-1.0.1-cuda1 100%[++++===============>] 344.60M 4.14MB/s 用时 2m 19ss 2020-08-17 12:07:57 (1.89 MB/s) - 已保存 “pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2” [361340025/361340025])
进入主目录执行安装:
conda install pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2
(pytorch) root@yy:~# ls anaconda3 公共的 图片 音乐 NVIDIA_CUDA-10.0_Samples 模板 文档 桌面 pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2 视频 下载 (pytorch) root@yy:~# conda install pytorch-1.0.1-cuda100py37he554f03_0.tar.bz2 Downloading and Extracting Packages ######################################################################## | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done
最后安装torchvision:
conda install torchvision
-
检查pytorch是否安装成功:
(pytorch) root@yy:~# python >>> import torch >>> print(torch.version) <module 'torch.version' from '/home/yy/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/version.py'> >>> print(torch.cuda.is_available()) True
看到返回值为Ture,说明pytorch安装成功。
ubuntu18.04+cuda10.0+anaconda3安装pytorch记录
最新推荐文章于 2023-06-17 20:15:33 发布