Linux中miniconda的操作

一、 miniconda的安装及环境配置

  1. 第一步下载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
    
  2. 第二步安装
    bash Miniconda3-py39_4.9.2-Linux-x86_64.sh
    # 或者
    sh Miniconda3-py39_4.9.2-Linux-x86_64.sh
    
  3. 第三部配置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
    
  1. 第四步创建一个名称为python3.7的环境,python版本等于3.7
    conda create -n name python=3.7  # 版本可自行选择
    
  2. 第五步 激活环境
    source activate python37
    

二、常用命令

  1. 创建环境
    conda create -n 环境名 python=3.7  # 版本可自行选择
    
  2. 进入创建的环境
    conda activate 环境名
    
  3. 查看已有环境
    conda info --env
    # 或
    conda info -e
    
  4. 查看已有安装包
    conda list
    
  5. 退出环境
    conda deactivate
    
  6. 删除某个环境
    conda remove -n 环境名 --all
    
  7. 删除某个环境下的某个包
    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/
  1. 临时使用

    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
    
  2. 永久使用
    前提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
    

四、设置操作命令

  1. 关闭自动进入conda基础环境

    conda config --set auto_activate_base false
    
  2. 开启自动进入conda基础环境

    conda config --set auto_activate_base true
    
  3. 要将某个 Conda 环境设置为默认环境

    • 通过修改 .bashrc 或 .zshrc 文件
      打开终端,编辑 .bashrc 或 .zshrc 文件(根据你使用的 Shell 决定)。

      nano ~/.bashrc   # 如果你使用的是 Bash
      # 或
      nano ~/.zshrc   # 如果你使用的是 Zsh
      
    • 在文件的末尾添加以下行
      将 your_env_name 替换为你希望设置为默认的环境名称:

      conda activate your_env_name
      # 保存并退出编辑器。
      
    • 重新加载配置文件,或者重启终端:

      source ~/.bashrc
      # 或
      source ~/.zshrc
      
  4. 查看帮助信息

    conda config -h
    
  5. 查看全部配置

    conda config --show
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌.云諾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值