Linux系统上搭建pytorch环境

具体步骤如下:

1、安装miniconda:download

sh Miniconda3-latest-Linux-x86_64.sh

安装过程逐步输入:yes;安装路径;no(最好自己手动将安装的路径bin添加到环境变量./bashrc中):

sudo gedit ~/.bashrc
export PATH=/home/lzm/miniconda3/bin:$PATH
source ~/.bashrc
终端输入conda,测试一下是否安装成功。

2 、添加国内源(加速安装过程):

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/msys2/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

3、创建pytorch环境:

下载对应版本的torch和torchvision:

https://download.pytorch.org/whl/cu102/torch/
https://download.pytorch.org/whl/cu102/torchvision/

conda create -n torch1.4 python=3.6 // torch1.4为环境名,自己可以随便创建

bug1:

若出现:
Collecting package metadata (current_repodata.json): failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json>
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.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

'https://repo.anaconda.com/pkgs/main/linux-64'

解决方法:
1. 在/home/username下打开.condarc
gedit .condarc
2. 注释掉defaults
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#  - defaults
show_channel_urls: true

bug2:

若出现:
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64/current_repodata.json>
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.
'https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64'

解决方法:
清空.condarc内容,再试!

4、查看环境:

conda info -e

5、激活环境:

source activate torch1.4

6、安装pytorch1.0:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch==1.4 torchvision==0.5.0

版本对应:

torch<=1.0 torchvision0.2.1
torch
1.7.0 torchvision0.8.1
torch
1.7.1 torchvision==0.8.2

conda install pytorch=1.4 torchvision -c pytorch

7、其他库的几种安装方式:

a.有requirements.txt文件时:

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

b.清华源: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
常用库:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Cython numba progress matplotlib tqdm opencv-python ipython numpy Pillow scikit-image pyyaml
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pycocotools 

c.conda:

conda install xxx

d.上面均无效时:

conda install -c menpo xxx
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值