Linux系统上搭建pytorch环境

本文介绍了在Linux系统下安装PyTorch环境的详细步骤,包括安装miniconda、添加国内源、创建pytorch环境、下载对应版本的torch和torchvision等,还提及了查看和激活环境、安装pytorch1.0的版本对应情况,以及其他库的几种安装方式。
部署运行你感兴趣的模型镜像

具体步骤如下:

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

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

为了在Linux搭建PyTorch环境,你可以按照以下步骤进行操作: 1. 使用conda安装PyTorch:可以使用以下命令安装指定版本的PyTorch和相关库: ``` conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch ``` \[1\] 2. 使用pip安装PyTorch:如果你更喜欢使用pip,可以使用以下命令安装指定版本的PyTorch和相关库: ``` pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch==1.4 torchvision==0.5.0 ``` \[2\] 3. 从官方网站下载安装包:你也可以从PyTorch官方网站下载适用于你的Linux系统的安装包。访问以下链接下载对应版本的PyTorch和torchvision安装包: ``` https://download.pytorch.org/whl/cu102/torch/ https://download.pytorch.org/whl/cu102/torchvision/ ``` 然后使用conda创建一个新的环境,并安装下载的安装包: ``` conda create -n torch1.4 python=3.6 conda activate torch1.4 pip install <path_to_downloaded_torch_whl_file> pip install <path_to_downloaded_torchvision_whl_file> ``` \[3\] 请根据你的需求选择其中一种方法进行PyTorch环境搭建。 #### 引用[.reference_title] - *1* [Linux系统下的pytorch环境配置](https://blog.youkuaiyun.com/hu_666666/article/details/127744620)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Linux系统搭建pytorch环境](https://blog.youkuaiyun.com/liuzhuomei0911/article/details/89784998)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值