1、Anaconda安装包下载

(1)官网下载,然后上传到服务器
(2)命令行下载
到下面网站上找到合适版本的anaconda
https://repo.anaconda.com/archive/
比如我选择了Anaconda3-2020.11-Linux-x86_64.sh这个版本的anaconda,然后通过下面命令进行下载

wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh

如果是其他版本,对应换掉archive后面的anaconda版本即可。

2、安装Anaconda

(1)进入文件下载目录 cd ~/software
(2)运行安装包

bash Anaconda3-2021.11-Linux-x86_64.sh

(3)回车键,进入注册信息页面
(4)按q跳过阅读,yes
(5)默认安装在用户目录下,直接回车即可安装;若想自定义安装目录,直接输入安装目录,回车即可。 等待一会安装完成。
请添加图片描述
(6)Do you wish the installer to initialize Anaconda3 by running conda init ? 输入 no,回车

3、修改环境变量

将Anaconda添加到用户环境变量中vim ~/.bashrc添加下面内容

这里写anaconda的安装路径

export PATH="/home/share/zhanghaoyu/anaconda3/bin:$PATH"

source一下

source ~/.bashrc

**可能出现的bug:**更新环境变量出错时如何处理
当使用source ./.bashrc,而出现大量命令无法找到时,如:请添加图片描述
解决:

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

4、检查是否安装成功

conda --version

5、换为清华源

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

6、 创建anaconda虚拟环境

这里我们用 Anaconda 的命令来创建虚拟环境。使用 conda create -n your_env_name python=X.X(2.7、3.6),使用该命令创建 python 版本为 X.X,名字为 your_env_name 的虚拟环境。your_env_name 文件可以在 Anaconda 安装目录 envs 文件下找到。

#创建虚拟环境
conda create -n your_env_name python=X.X(3.6、3.7等)
#第一次激活虚拟环境需要用source
source activate your_env_name(虚拟环境名称) 
#激活虚拟环境
conda activate your_env_name(虚拟环境名称)
#退出虚拟环境
conda deactivate
#查看当前存在哪些虚拟环境
conda env list
#或 
conda info -e
#或
conda info --envs
#删除虚拟环境
conda remove -n your_env_name(虚拟环境名称) --all
 conda remove --name your_env_name package_name  # 删除环境中的某个包
#查看安装了哪些包
conda list
#安装包
conda install package_name(包名)
conda install scrapy==1.3 # 安装指定版本的包
conda install -n 环境名 包名 # 在conda指定的某个环境中安装包
#检查更新当前conda
conda update conda
#更新anaconda
conda update anaconda
#更新所有库
conda update --all
#更新python
conda update python
安装requirements.txt依赖:
pip install -r requirements.txt

7、安装pytorch

进入pytorch官方网站获取安装指令
https://pytorch.org/
在官网主页根据你的系统和CUDA,python版本,选择conda安装方式。我的是

conda install pytorch torchvision torchaudio cudatoolkit=10.1

测试:
在环境下输入python然后测试

import torch
import torchvision
torch.__version__
torchvision.__version__
torch.cuda.is_available()

在这里插入图片描述

卸载torch和torchvision

pip uninstall torch
pip uninstall torchvision

如何安装与cuda适配的torch?
1.用nvidia-smi查看cuda版本
在这里插入图片描述
2.在这个官网查找torch版本:https://download.pytorch.org/whl/torch_stable.html
使用以下命令安装

pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐