基础环境(python,gpu等)

发布时间 2023-11-03 15:09:20作者: 15375357604

anaconda

清华镜像站中anaconda的所有版本的网址:Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

minianaconda:Index of / (anaconda.com) 

wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

也可以直接在linux上下载:

选择合适的版本,右键->复制链接地址。wget + 地址就可以下载了。wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh

bash Anaconda3-2021.11-Linux-x86_64.sh

conda create -n test python=3.7.5
conda activate test
conda deactivate
conda remove -n test --all # 删除创建的虚拟环境
conda create -n test --clone test2  # 复制虚拟环境
conda env list #查看虚拟环境

添加Anaconda的TUNA镜像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/



配置环境变量

通过:

vim /etc/profile

打开profile文件,在末尾添加:

PATH=$PATH:/data/home/halley/anaconda3/bin:$PATH

注意:/data/home/halley/anaconda3/bin是自己安装的路径,根据自己的情况设置。

最后更新配置:

source /etc/profile
 

安装需要的包

切换到使用的环境后,安装第三方库

①安装:conda install [包名]

conda install tensorflow-gpu # 安装TensorFlow
conda install numpy==1.18.5 # 指定安装版本号

②删除:conda uninstall [包名]

conda uninstall numpy

③更新:conda update [包名]

conda update numpy

(重要)复制环境依赖

这个方法一般是在复现相同环境时使用,一键快捷省心。例如更换服务器、复现git开源工程等。

①conda

conda导出已有的环境,保存在myenv.yaml文件中。

conda env export > myenv.yaml

根据yaml文件导入并安装环境

conda env create -f myenv.yaml

注:.yaml文件移植过来的环境只是原来环境里用conda install命令安装的包,pip安装的库可能不会移植过来,需要重新安装。

②pip

把环境中的依赖写入 requirement.txt 中

pip freeze >requirements.txt

安装环境依赖

pip install -r requirement.txt

1、安装

命令 "conda install jupyterlab"

Collecting package metadata (current_repodata.json): done
Solving environment: done
***
The following packages will be UPDATED:
 
 ca-certificates 2021.7.5-h06a4308_1 --> 2021.10.26-h06a4308_2
 certifi 2021.5.30-py39h06a4308_0 --> 2021.10.8-py39h06a4308_0
 openssl 1.1.1k-h27cfd23_0 --> 1.1.1l-h7f8727e_0
 
Proceed ([y]/n)? y
***
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

2、启动

命令 “jupyter-lab“