一、 miniconda的安装及环境配置
- 第一步下载miniconda安装包
安装包连接https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/,查找相应安装包wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
- 第二步安装
bash Miniconda3-py39_4.9.2-Linux-x86_64.sh # 或者 sh Miniconda3-py39_4.9.2-Linux-x86_64.sh
- 第三部配置conda镜像
source ~/.bashrc 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/bioconda conda config --set show_channel_urls yes
- 正常情况下重新打开一个终端后默认的环境就是conda的默认base环境。如果不生效的话请执行以下操作
#conda,这是把conda的环境加入系统的环境变量 export conda=/root/miniconda3 export PATH=$PATH:$conda/bin # 这一步是系统进入conda的默认base环境 source activate
- 第四步创建一个名称为python3.7的环境,python版本等于3.7
conda create -n name python=3.7 # 版本可自行选择
- 第五步 激活环境
source activate python37
二、常用命令
- 创建环境
conda create -n 环境名 python=3.7 # 版本可自行选择
- 进入创建的环境
conda activate 环境名
- 查看已有环境
conda info --env # 或 conda info -e
- 查看已有安装包
conda list
- 退出环境
conda deactivate
- 删除某个环境
conda remove -n 环境名 --all
- 删除某个环境下的某个包
conda remove -n 环境名 包名
三、配置镜像源
- 清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/
- 阿里云:http://mirrors.aliyun.com/pypi/simple/
- 中国科学技术大学 :http://pypi.mirrors.ustc.edu.cn/simple/
- 华中科技大学:http://pypi.hustunique.com/
- 豆瓣源:http://pypi.douban.com/simple/
- 腾讯源:http://mirrors.cloud.tencent.com/pypi/simple
- 华为镜像源:https://repo.huaweicloud.com/repository/pypi/simple/
-
临时使用
pip install [包名] -i [pip源URL] # 示例 pip install pytest -i https://pypi.tuna.tsinghua.edu.cn/simple # 或 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytest # 或 pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
-
永久使用
前提pip版本 (>=10.0.0) 方可使用此命令进行配置:升级 pip 到最新的版本
pip install pip -U # 或 python -m pip install --upgrade pip
修改pip源为清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
四、设置操作命令
-
关闭自动进入conda基础环境
conda config --set auto_activate_base false
-
开启自动进入conda基础环境
conda config --set auto_activate_base true
-
要将某个 Conda 环境设置为默认环境
-
通过修改 .bashrc 或 .zshrc 文件
打开终端,编辑 .bashrc 或 .zshrc 文件(根据你使用的 Shell 决定)。nano ~/.bashrc # 如果你使用的是 Bash # 或 nano ~/.zshrc # 如果你使用的是 Zsh
-
在文件的末尾添加以下行
将 your_env_name 替换为你希望设置为默认的环境名称:conda activate your_env_name # 保存并退出编辑器。
-
重新加载配置文件,或者重启终端:
source ~/.bashrc # 或 source ~/.zshrc
-
-
查看帮助信息
conda config -h
-
查看全部配置
conda config --show