常用命令
pip 常用命令
默认情况下,GPUGEEK 平台的 pip
命令是使用 miniconda3
进行安装,可以通过如下 pip -V
命令查看 pip
安装目录。
查看pip命令安装目录
pip -V
查看pip命令执行程序位置
command -V pip
查看当前 pip 版本
pip --version
列出所有已安装的包
pip list
安装最新版本的 numpy 库
pip install numpy
pip 卸载指定库
pip uninstall numpy
pip 指定版本安装指定包
pip install numpy==1.26.1
pip 搜索指定包可安装的所有版本
pip install numpy==
#也可以到 https://pypi.org/ 官网取搜索指定库,然后查看 Release history
pip 指定源安装指定库,适用于当前源安装该库较慢,临时切换源使用
pip install numpy -i https://pypi.doubanio.com/simple/
pip 指定文件批量安装库,在requirements.txt文件中定义需要安装的库
pip install -r requirements.txt
指定文件批量卸载库
pip uninstall -r requirements.txt
通过 pip 下载指定包到指定目录,但不安装它
pip download numpy -d /gz-data/
pip 指定已下载或者已克隆的包进行安装
pip install ./gz-data/numpy-1.26.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pip 查看指定包的兼容性
pip check numpy
pip 查看已安装库的详细信息
pip show numpy
查询当前可升级的 pip 库
pip list --outdated
pip 升级指定安装包
pip install --upgrade numpy
pip 升级 pip 自身
pip install --upgrade pip
pip查看当前源配置
pip config list
永久性修改 pip 源
pip config set global.index-url --site https://pypi.tuna.tsinghua.edu.cn/simple
查看 pip 下载的安装包的默认路径
python3 -m site
conda 常用命令
查看 conda 版本
conda --version
查看 conda 信息
conda info
更新 conda 自身到最新版本,同时也会更新其它包
conda update conda
conda 更新指定包,这里更新通过 conda 安装的 zlib 包
conda update zlib
列出所有虚拟环境
conda env list
conda info -e
创建一个 python 版本为 3.8.10 的虚拟环境
conda create -n GPUGEEK python==3.8.10
切换到名称为 GPUGEEK 的虚拟环境
conda activate GPUGEEK
退出当前虚拟环境
conda deactivate
删除指定虚拟环境
conda remove --name GPUGEEK --all
查看已安装的包
conda list
指定目录创建虚拟环境
conda create -p /gz-data/myenv python=3.8.10
安装 numpy 指定包到当前虚拟环境
conda install numpy
在指定虚拟环境中安装包,这里在 GPUGEEK 虚拟环境中安装 nmupy 包
conda install --name GPUGEEK numpy
删除或者卸载当前虚拟环境中的指定包
conda remove numpy
删除或者卸载指定虚拟环境中安装包,这里在 GPUGEEK 虚拟环境中删除 nmupy 包
conda remove --name GPUGEEK numpy
搜索 numpy 包的所有版本
conda search numpy
搜索大于或等于 1.24 版本以上的 numpy 包
conda search 'numpy>=1.24'
通过 conda 安装包后,conda 会在 /root/.cache/conda
目录下生成缓存,可以通过如下命令查看该目录缓存
du -sh /root/.cache/conda/
如果 /root/.cache/conda
目录缓存较大,则可以通过如下命令清理 conda 缓存
conda clean --all
从 GPUGEEK
虚拟环境来克隆一个名称为 gm
的新虚拟环境
conda create --name gm --clone GPUGEEK
导出虚拟环境中所安装的所有包到指定文件
conda env export --name gm > gm.yml
删除指定虚拟环境
conda env remove --name gm
实例中压缩及解压命令
在实例中的压缩及解压缩命令常用到的有如下: tar、zip、unzip、gzip、gunzip、7z、bzip2、bunzip2、xz、unxz、rar、unrar等。
tar命令进行压缩及解压
#将 file_or_directory 文件或目录压缩为 archive.tar
tar -cvf archive.tar file_or_directory
#将多个文件或目录压缩到同一个文件中,这里将 file1 file2 directory1 directory2 一起压缩为 archive.tar 文件
tar -cvf archive.tar file1 file2 directory1 directory2
#解压缩 archive.tar 文件到当前目录
tar -xvf archive.tar
#解压缩 archive.tar 到 /gz-data/ 目录下
tar -xvf archive.tar -C /gz-data/
zip 及 unzip 命令进行压缩和解压
zip 和 unzip 算是一对命令,zip 命令用来压缩,unzip 用来解压 zip 命令的压缩。
#将 file_or_directory 文件或目录压缩为 archive.zip
zip -r archive.zip file_or_directory
#将多个文件或目录压缩到同一个文件中,这里将 file1 file2 directory1 directory2 一起压缩为 archive.zip 文件
zip -r archive.zip file1 file2 directory1 directory2
#解压缩 archive.zip 文件到当前目录
unzip archive.zip
#解压缩 archive.zip 到 /gz-data/ 目录下
unzip archive.zip -d /gz-data/
gzip 及 gunzip 命令进行压缩和解压
gzip 和 gunzip 也算是一对命令,gzip 命令用来压缩,gunzip 用来解压 gzip 命令的压缩。
#压缩文件名为 file 的文件
gzip file
#解压通过 gzip 压缩的文件
gunzip file.gz
7z 命令进行压缩及解压缩
#将 file_or_directory 文件或目录压缩为 archive.7z
7z a archive.7z file_or_directory
#将多个文件或目录压缩到同一个文件中,这里将 file1 file2 directory1 directory2 一起压缩为 archive.7z 文件
7z a archive.7z file1 file2 directory1 directory2
#解压缩 archive.7z 文件到当前目录
7z x archive.7z
#解压缩 archive.7z 到 /gz-data/ 目录下,注意 -o/gz-data/ 之间没有空格
7z x archive.7z -o/gz-data/
bzip2 及 bunzip2 命令进行压缩和解压
bzip2 和 bunzip2 也算是一对命令,bzip2 命令用来压缩,bunzip2 用来解压 bzip2 命令的压缩。
#压缩文件名为 file 的文件
bzip2 file
#解压通过 gzip 压缩的文件
bunzip2 file.bz2
xz 及 unxz 命令进行压缩和解压
xz 和 unzx 也算是一对命令,xz 命令用来压缩,unxz 用来解压 xz 命令的压缩。
#压缩文件名为 file 的文件
xz file
#解压通过 gzip 压缩的文件
unxz file.bz2
rar 及 unrar 命令进行压缩和解压
#将 file_or_directory 文件或目录压缩为 archive.rar
rar a archive.rar file_or_directory
#将多个文件或目录压缩到同一个文件中,这里将 file1 file2 directory1 directory2 一起压缩为 archive.rar 文件
rar a archive.rar file1 file2 directory1 directory2
#解压缩 archive.rar 文件到当前目录
unrar x archive.rar
#解压缩 archive.rar 到 /gz-data/ 目录下
unrar x archive.rar /gz-data/
apt 安装及卸载软件包命令
更新本地软件包列表,更新镜像源
sudo apt-get update -y
安装指定软件包,前提是需要知道包名
sudo apt-get install busybox -y
卸载软件包但需要保留配置文件
sudo apt-get remove busybox -y