zoukankan      html  css  js  c++  java
  • ✍32 anaconda安装及使用

    anaconda简介

    • Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项。 [1] 因为包含了大量的科学包,Anaconda 的下载文件比较大(约 531 MB),如果只需要某些包,或者需要节省带宽或存储空间,也可以使用Miniconda这个较小的发行版(仅包含conda和 Python)

    Windows 安装:

    https://blog.csdn.net/weixin_50888378/article/details/109022585
    

    Linux 安装 :

    https://blog.csdn.net/ychgyyn/article/details/82258136
    
    • 下载
    wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
    
    • 执行bash
    bash Anaconda3-5.0.1-Linux-x86_64.sh
    

    安装---> 默认时yes--->最后是否加入环境变量(如果不小心 NO)往下看

    • 会提示你是否安装一个 vscode, 不需要安装选择 no
    • 添加环境变量(profile 和 bashrc 都可以)
    export PATH=/home/(your_n)/anaconda3/bin:$PATH  # 默认是root下
    source .bashrc
    

    会在安装目录下生成anaconda的文件夹。之后所安装的虚拟环境均存在env文件夹中

    • 查看安装成功?

    image-20210823102912082

    • 安装Python依赖包
    #安装pymc
    conda install pymc
    #python中import
    import pymc
    

    卸载

    • 删除Anaconda
    #删除Anaconda安装文件
    rm -rf /usr/local/anaconda2
    #删除路径配置 (profile 或者 bashrc (k自己写在哪里))
    vim /etc/profile
    export PATH=/usr/local/anaconda2/bin:$PATH"这一行删除!
    source  /etc/profile && bash
    

    基本使用命令 / 虚拟环境操作

    • 查看安装成功
    conda --version
    
    • 查看当前存在哪些环境
    conda env list
    
    • 创建虚拟环境
    conda create -n 虚拟环境名 python=版本号
    
    • 激活(进入)虚拟环境
    source activate your_env_name
    conda activate 虚拟环境名  # 或者(w)
    
    conda activate python37  # 切换到 python37环境
    
    • 关闭(退出)虚拟环境
    source deactivate
    conda deactivate  # 或者 
    
    • 删除虚拟环境及下属所有包
    conda remove -n your_env_name --all
    
    • 打包环境 : 将当前使用的环境中所包含的python包的名称进行打包
    • 导出当前环境的包信息
    conda env export > 文件名.yaml
    
    • 载入环境
    • 用配置文件创建新的虚拟环境
    conda env update -f=/path/文件名.yml
    

    模块安装(没什么变化)

    • 安装1
    conda list  # 列出当前环境的所有包
    conda install requests  # 安装requests包
    conda remove requests  # 卸载requets包
    conda remove -n python37–all  # 删除learn环境及下属所有包
    conda update requests  # 更新requests包
    
    • 安装2
    # 如果已经在虚拟环境中,可以直接安装
    pip install XXX
    
    # 也可以使用conda命令安装到某個虚拟环境中
    conda install -n [虛擬環境名稱] xxx
    
    • requirement.txt 安装跳过 不能安装的包, 配置如下py脚本执行
    import sys
    from pip._internal import main as pip_main
     
    def install(package):
        pip_main(['install', package])
     
    if __name__ == '__main__':
        with open(sys.argv[1]) as f:
            for line in f:
                install(line)
    

    修改下载源

    1.通过修改配置文件

    • /home/你的用户名/.condarc
    # 清华镜像anaconda源
    channels:
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    ssl_verify: true
    
    
    # 上海交大anaconda镜像源
    channels:
      - https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
      - https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
      - https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
    ssl_verify: true
    
    
    # 中科大anaconda镜像源
    channels:
      - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
      - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
      - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
    ssl_verify: true
    

    2.通过镜像源添加命令

    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/
    
    

    删除镜像源

    conda config --remove-key channels
    
  • 相关阅读:
    js对象,数组,字符串的操作
    js 类型之间的相互转化
    Spark常见问题汇总
    Spark RDD的默认分区数:(spark 2.1.0)
    手动合并hadoop namenode editlog
    Yarn参数优化(Fair Scheduler版本)
    linux中在某个目录下多个文件中搜索关键字
    JDK中jps、jinfo、jstat、jstack、jmap、jconsole等命令简介
    Elasticsearch 为何要在 7.X版本中 去除type 的概念
    Linux 查看内存使用情况
  • 原文地址:https://www.cnblogs.com/songhaixing/p/15605524.html
Copyright © 2011-2022 走看看