章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • python

    • python基础

      • python基础知识
      • python基础较难的15个知识点
    • FastAPI

    • python每日练习脚本

    • python3给防火墙添加放行
    • python生成部署脚本
    • python将多个文件内容输出到一个文件中
    • 使用 Aligo 定时备份服务器文件
    • python监控日志文件并发送钉钉告警
    • python监控数据库脚本并发送钉钉告警
    • 使用python编写自动化发布脚本
    • 查询redis列表某个元素
    • centos7安装python3
    • python环境管理工具介绍
    • conda安装和镜像源配置
      • pip更换国内源
      • python爬虫
      • python环境启动服务报错缺少glibc库版本
      • 监控目录或文件变化
      • 批量更改文件
      • python引用数据库
    • shell

    • go

    • 编程
    • python
    章工运维
    2024-07-31
    目录

    conda安装和镜像源配置

    # 安装

    Miniconda清华源 (opens new window)

    bash Miniconda-3.9.1-Linux-x86_64.sh -b -u -p /usr/local/miniconda3
    
    1

    # 配置

    #生成配置文件
    conda config
    
    1
    2

    # 查看当前源

    conda config --show channels
    
    1

    # 替换源

    conda config --add channels https://xxxxxxxxxxxxxxx
    
    1

    针对清华源和腾讯源替换的方法

    清华源

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    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/pytorch/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
    
    1
    2
    3
    4
    5

    腾讯源

    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/conda-forge/
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/pytorch/
    conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/pro/
    
    1
    2
    3
    4
    5

    # 移除源

    conda config --remove channels https://xxxxxxxxxxxxxxx
    
    1

    针对清华源和腾讯源移除的方法

    清华源

    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
    
    1
    2
    3
    4
    5

    腾讯源

    conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/
    conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/
    conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/cloud/conda-forge/
    conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/cloud/pytorch/
    conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/pro/
    
    1
    2
    3
    4
    5

    # 使用配置文件修改

    使用文档编辑工具打开 ~/.condarc 文件,即可手动修改配置信息。

    channels:
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
      - defaults
    show_channel_urls: true
    
    1
    2
    3
    4
    5
    6
    7
    8

    # 使用 conda 创建一个新的虚拟环境,并安装兼容的 Python 版本

    conda create -n tf2 python=3.9
    conda activate tf2
    
    1
    2

    # 导出现有环境的python依赖

    python -m pip freeze > requirements.txt
    pip install -r requirements.txt
    #指定镜像源安装
    pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    1
    2
    3
    4

    # 在 Windows 系统上运行 Python 应用,创建虚拟环境(virtual environment)的方法很简单。这里是标准步骤:

    # 1. 安装 Python

    确认你已经安装了 Python,并且安装时勾选了 "Add Python to PATH"。
    可以打开命令行(cmd)输入:

    python --version
    
    1

    确认能看到版本号。


    # 2. 安装 virtualenv(可选)

    虽然 Python 3.3+ 自带了 venv 模块,不需要额外安装,但有些人喜欢用 virtualenv。如果想用它,可以安装:

    pip install virtualenv
    
    1

    # 3. 使用 venv 创建虚拟环境(推荐)

    在你的项目目录下,比如 D:\myproject,打开命令行,运行:

    cd D:\myproject
    python -m venv venv
    
    1
    2

    这会在 D:\myproject\venv\ 目录里创建一个虚拟环境。


    # 4. 启动虚拟环境

    在 Windows 上激活虚拟环境,命令是:

    venv\Scripts\activate
    
    1

    激活后,命令行前面会出现 (venv),表示虚拟环境已经启用。


    # 5. 安装依赖

    虚拟环境激活后,你可以用 pip 安装项目需要的库,比如:

    pip install -r requirements.txt
    
    1

    # 6. 退出虚拟环境

    用完之后,退出虚拟环境,可以输入:

    deactivate
    
    1

    参考链接 (opens new window)

    微信 支付宝
    上次更新: 2025/04/27, 17:35:39

    ← python环境管理工具介绍 pip更换国内源→

    最近更新
    01
    shell脚本模块集合
    05-13
    02
    生活小技巧(认知版)
    04-29
    03
    生活小技巧(防骗版)
    04-29
    更多文章>
    Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式