1.下载anaconda:
清华源镜像:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=A,从中下载Linux版本的anaconda
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
2.安装命令:
chmod 777 Anaconda3-2023.09-0-Linux-x86_64.sh
bash Anaconda3-2023.09-0-Linux-x86_64.sh [可选项] [-u 修改安装] [-p /data/anaconda3 修改安装目录]ye's
安装环境:
no change /home/anaconda3/condabin/conda
no change /home/anaconda3/bin/conda
no change /home/anaconda3/bin/conda-env
no change /home/anaconda3/bin/activate
no change /home/anaconda3/bin/deactivate
no change /home/anaconda3/etc/profile.d/conda.sh
no change /home/anaconda3/etc/fish/conf.d/conda.fish
no change /home/anaconda3/shell/condabin/Conda.psm1
no change /home/anaconda3/shell/condabin/conda-hook.ps1
no change /home/anaconda3/lib/python3.11/site-packages/xontrib/conda.xsh
no change /home/anaconda3/etc/profile.d/conda.csh
modified /home/.bashrc
3.测试是否安装成功
输入命令conda --version
,有版本信息则说明安装成功,否则可能没有在步骤2中没有将conda加入环境变量中,需执行:
export PATH=/home/anaconda3/bin:$PATH
export PATH=/data/anaconda3/bin:$PATH
source /home/.bashrc
4.创建虚拟环境
conda create -n py38 python=3.8
5.激活虚拟环境
conda activate py38
若报错CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'
,则执行:
source ~/anaconda3/etc/profile.d/conda.sh
6.退出虚拟环境
conda activate
7.查看已存在虚拟环境
conda env list
8.删除虚拟环境
conda remove -n py37 --all
9.打包当前虚拟环境中用到的所有python包
conda env export > py37.yaml
10.加载打包的虚拟环境
conda create -n py37 -f py37.yaml
11.安装未安装的第三方库–加上清华源
pip install [name] -i https://pypi.tuna.tsinghua.edu.cn/simple
镜像站名 网址
清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云: https://mirrors.aliyun.com/pypi/simple/
豆瓣: https://pypi.douban.com/simple/
腾讯: http://mirrors.cloud.tencent.com/pypi/simple
12.python nohup命令
nohup是一个Linux命令,是no hangup的缩写,意思是不挂断。它常用于在服务器上执行耗时较长的程序或者脚本,并且需要将程序在后台运行,即时退出ssh远程终端也不会停止程序的运行。使用nohup命令可以将程序即时分离,不受终端退出的影响,使程序持续进行。下面是nohup命令执行python脚本的基本使用语法:
nohup python “脚本名” &
–>会自动将结果输出到 nohup.out 脚本中,当然我们也可以让其输出到固定脚本中。
(2)将nohup输出重定向到文件
默认情况下,nohup会将程序的输出发送到标准输出,即终端窗口。如果我们希望将输出保存到文件中,可以使用输出重定向符号(>&)将输出重定向到一个文件中。例如,我们可以将test.py的输出保存到output.log中:
nohup python test.py > output.log 2>&1 &
(3)查看 nohup进程
如果我们希望查看当前正在运行的nohup进程,可以使用如下命令:
ps -ef | grep ‘nohup’
13.查看cuda和torch版本
import torch
print(torch.__version__) #查看torch版本
print(torch.version.cuda) #查看cuda版本
import torchvision
print(torchvision.__version__)#查看torchvision的版本
14.下载torch和torchvision
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
# 可以访问https://download.pytorch.org/whl/torch_stable.html下载对应版本的torch和cuda和torchvision,然后
# pip install + *.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
# 这种方法可以避免从pytorch官网下载安装包,速度较快
# 在anaconda虚拟环境中安装torch和cuda
conda install torch=1.7.1 cudatoolkit=11.0 -c pytorch
conda install torch=1.8.0 cudatoolkit=11.1 -c pytorch
15.查看某个安装包的历史版本号
pip index versions [pak]
16.某个库安装不成功
1.从python.org网站上下载.whl文件然后手动pip install *.whl -i [源]
2.查看gcc的版本是否对应