zoukankan      html  css  js  c++  java
  • Ubuntu / CentOS 安装 Anaconda 并创建虚拟环境

    Anaconda可以很好地帮我们管理Python的虚拟环境,Windows上操作极其方便,现在讲一下 Ubuntu 和 CentOS 上的使用方法

    ubuntu 安装Anaconda版本

    安装方法一:

    1. 官网下载地址:https://www.anaconda.com/distribution/#download-section 
    2. 打开terminal,执行安装命令
      # 可以先创建一个文件夹
      mkdir Anaconda
      cd Anaconda
      # 安装命令,sh后面跟的就是下载好的文件 sh /root/Downloads/Anaconda2-2019.03-Linux-x86_64.sh
    3. 注册信息,输入yes;
    4. 阅读注册信息,然后输入yes;查看文件即将安装的位置(默认路径为 /root/anaconda3,可自行修改),按enter,即可安装;
    5. 安装完成后,收到加入环境变量的提示信息,输入yes,(默认按回车的话为no,需要手动设置环境变量)
    6. 安装完成后重启终端就行了

    安装方法二:

    • 我们先建一个文件夹,用于安装路径
      # 安装路径为 /root/Anaconda
      cd /root
      mkdir Anaconda
      cd Anaconda
    • 命令行运行下载命令
      wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
    • 命令行运行安装命令
      bash Anaconda3-5.2.0-Linux-x86_64.sh
    • 之后的步骤同方法一的3、4、5、6

    CentOS 安装 Anaconda

    • 先建立一个文件夹用于作为安装路径
      # 安装路径为 /root/Anaconda
      cd /root
      mkdir Anaconda
      cd Anaconda
    • 命令行下载 anaconda 文件,文件列表的 URL 为:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/,根据需求自己选择一个版本(下面使用的是anaconda2版本)
      # 如果没有安装 wget 运行下面这行
      yum install wget
      
      # 下载 anaconda 文件
      wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda2-5.3.1-Linux-x86_64.sh
    • 执行安装命令
      # 安装命令
      bash Anaconda2-5.3.1-Linux-x86_64.sh 
      
      '''
      如果报错
      Anaconda2-5.3.1-Linux-x86_64.sh: line 353: bunzip2: command not found
      tar: This does not look like a tar archive
      tar: Exiting with failure status due to previous errors
      由于系统缺少bunzip2包造成的,通过yum安装bzip2包来解决
      运行下面的命令
      '''
      yum install bzip2
    • 之后的步骤同 Ubuntu 第一种安装方法的3、4、5、6

    Anaconda 相关命令

    # 1.设置环境变量:下面的路径需要改成自己的 bin 文件夹所在的路径
    export PATH=~/Anaconda/anaconda3/bin:$PATH
    vim /root/.bashrc
    source /root/.bashrc
    
    # 2.查看安装版本
    conda -V
    
    # 3.查看可用包列表
    conda list # 列表有则表示安装成功
    
    # 4.查找可用版本
    conda search "^python$"
    '''
    python                         1.0.1               0  pkgs/free           
    python                         2.6.8               1  pkgs/free           
    python                         2.6.8               2  pkgs/free           
    python                         2.6.8               3  pkgs/free           
    python                         2.6.8               4  pkgs/free           
    python                         2.6.8               5  pkgs/free           
    python                         2.6.8               6  pkgs/free           
    python                         2.6.8               7  pkgs/free           
    python                         2.6.9               0  pkgs/free           
    python                         2.6.9               1  pkgs/free           
    python                         2.7.3               2  pkgs/free           
    python                         2.7.3               3  pkgs/free           
    python                         2.7.3               4  pkgs/free           
    python                         2.7.3               5  pkgs/free           
    python                         2.7.3               6  pkgs/free           
    python                         2.7.3               7  pkgs/free           
    python                         2.7.4               0  pkgs/free           
    python                         2.7.5               0  pkgs/free           
    python                         2.7.5               1  pkgs/free           
    python                         2.7.5               2  pkgs/free           
    python                         2.7.5               3  pkgs/free           
    python                         2.7.6               0  pkgs/free           
    python                         2.7.6               1  pkgs/free           
    python                         2.7.6               2  pkgs/free           
    python                         2.7.7               0  pkgs/free           
    python                         2.7.7               2  pkgs/free           
    python                         2.7.8               0  pkgs/free           
    python                         2.7.8               1  pkgs/free           
    python                         2.7.9               0  pkgs/free           
    python                         2.7.9               1  pkgs/free           
    python                         2.7.9               2  pkgs/free           
    python                         2.7.9               3  pkgs/free           
    python                         2.7.9              d1  pkgs/free           
    python                         2.7.9              d2  pkgs/free           
    python                        2.7.10               0  pkgs/free           
    python                        2.7.10               1  pkgs/free           
    python                        2.7.10               2  pkgs/free           
    python                        2.7.10              d0  pkgs/free           
    python                        2.7.11               0  pkgs/free           
    python                        2.7.11               5  pkgs/free           
    python                        2.7.11              d0  pkgs/free           
    python                        2.7.12               0  pkgs/free           
    python                        2.7.12               1  pkgs/free           
    python                        2.7.13               0  pkgs/free           
    python                        2.7.13     hac47a24_15  pkgs/main           
    python                        2.7.13     heccc3f1_16  pkgs/main           
    python                        2.7.13     hfff3488_13  pkgs/main           
    python                        2.7.14     h1571d57_29  pkgs/main           
    python                        2.7.14     h1571d57_30  pkgs/main           
    python                        2.7.14     h1571d57_31  pkgs/main           
    python                        2.7.14     h1aa7481_19  pkgs/main           
    python                        2.7.14     h435b27a_18  pkgs/main           
    python                        2.7.14     h89e7a4a_22  pkgs/main           
    python                        2.7.14     h91f54f5_26  pkgs/main           
    python                        2.7.14     h931c8b0_15  pkgs/main           
    python                        2.7.14     h9b67528_20  pkgs/main           
    python                        2.7.14     ha6fc286_23  pkgs/main           
    python                        2.7.14     hc2b0042_21  pkgs/main           
    python                        2.7.14     hdd48546_24  pkgs/main           
    python                        2.7.14     hf918d8d_16  pkgs/main           
    python                        2.7.15      h1571d57_0  pkgs/main           
    python                        2.7.15      h77bded6_1  pkgs/main           
    python                        2.7.15      h77bded6_2  pkgs/main           
    python                        2.7.15      h9bab390_2  pkgs/main           
    python                        2.7.15      h9bab390_4  pkgs/main           
    python                        2.7.15      h9bab390_6  pkgs/main           
    python                        2.7.16      h9bab390_0  pkgs/main           
    python                         3.3.0               2  pkgs/free           
    python                         3.3.0               3  pkgs/free           
    python                         3.3.0               4  pkgs/free           
    python                         3.3.1               0  pkgs/free           
    python                         3.3.2               0  pkgs/free           
    python                         3.3.2               1  pkgs/free           
    python                         3.3.3               0  pkgs/free           
    python                         3.3.4               0  pkgs/free           
    python                         3.3.5               0  pkgs/free           
    python                         3.3.5               1  pkgs/free           
    python                         3.3.5               2  pkgs/free           
    python                         3.3.5               3  pkgs/free           
    python                         3.3.5               4  pkgs/free           
    python                         3.4.0               0  pkgs/free           
    python                         3.4.1               0  pkgs/free           
    python                         3.4.1               1  pkgs/free           
    python                         3.4.1               2  pkgs/free           
    python                         3.4.1               3  pkgs/free           
    python                         3.4.1               4  pkgs/free           
    python                         3.4.2               0  pkgs/free           
    python                         3.4.3               0  pkgs/free           
    python                         3.4.3               1  pkgs/free           
    python                         3.4.3               2  pkgs/free           
    python                         3.4.4               0  pkgs/free           
    python                         3.4.4               5  pkgs/free           
    python                         3.4.5               0  pkgs/free           
    python                      3.5.0rc4               0  pkgs/free           
    python                         3.5.0               0  pkgs/free           
    python                         3.5.0               1  pkgs/free           
    python                         3.5.1               0  pkgs/free           
    python                         3.5.1               5  pkgs/free           
    python                         3.5.2               0  pkgs/free           
    python                         3.5.3               0  pkgs/free           
    python                         3.5.3               1  pkgs/free           
    python                         3.5.4               0  pkgs/free           
    python                         3.5.4     h00c01ad_19  pkgs/main           
    python                         3.5.4     h0b4c808_22  pkgs/main           
    python                         3.5.4     h2170f06_12  pkgs/main           
    python                         3.5.4     h3075507_18  pkgs/main           
    python                         3.5.4     h417fded_24  pkgs/main           
    python                         3.5.4     h56e0582_23  pkgs/main           
    python                         3.5.4     h72f0b78_15  pkgs/main           
    python                         3.5.4     hb43c6bb_21  pkgs/main           
    python                         3.5.4     hc053d89_14  pkgs/main           
    python                         3.5.4     hc3d631a_27  pkgs/main           
    python                         3.5.4     he2c66cf_20  pkgs/main           
    python                         3.5.5      hc3d631a_0  pkgs/main           
    python                         3.5.5      hc3d631a_1  pkgs/main           
    python                         3.5.5      hc3d631a_3  pkgs/main           
    python                         3.5.5      hc3d631a_4  pkgs/main           
    python                         3.5.6      hc3d631a_0  pkgs/main           
    python                         3.6.0               0  pkgs/free           
    python                         3.6.1               0  pkgs/free           
    python                         3.6.1               2  pkgs/free           
    python                         3.6.2               0  pkgs/free           
    python                         3.6.2     h02fb82a_12  pkgs/main           
    python                         3.6.2     h0b30769_14  pkgs/main           
    python                         3.6.2     h33255ae_18  pkgs/main           
    python                         3.6.2     hca45abc_19  pkgs/main           
    python                         3.6.2     hdfe5801_15  pkgs/main           
    python                         3.6.3      h0ef2715_3  pkgs/main           
    python                         3.6.3      h1284df2_4  pkgs/main           
    python                         3.6.3      h6c0c0dc_5  pkgs/main           
    python                         3.6.3      hc9025b9_1  pkgs/main           
    python                         3.6.3      hcad60d5_0  pkgs/main           
    python                         3.6.3      hefd0734_2  pkgs/main           
    python                         3.6.4      hc3d631a_0  pkgs/main           
    python                         3.6.4      hc3d631a_1  pkgs/main           
    python                         3.6.4      hc3d631a_3  pkgs/main           
    python                         3.6.5      hc3d631a_0  pkgs/main           
    python                         3.6.5      hc3d631a_1  pkgs/main           
    python                         3.6.5      hc3d631a_2  pkgs/main           
    python                         3.6.6      h6e4f718_2  pkgs/main           
    python                         3.6.6      hc3d631a_0  pkgs/main           
    python                         3.6.7      h0371630_0  pkgs/main           
    python                         3.6.8      h0371630_0  pkgs/main           
    python                         3.7.0      h6e4f718_3  pkgs/main           
    python                         3.7.0      hc3d631a_0  pkgs/main           
    python                         3.7.1      h0371630_3  pkgs/main           
    python                         3.7.1      h0371630_7  pkgs/main           
    python                         3.7.2      h0371630_0  pkgs/main           
    python                         3.7.3      h0371630_0  pkgs/main  
    '''
    
    # 5.创建新的虚拟环境
    conda create --name my_env python=3.7.3
    
    # 6.激活新环境
    source activate my_env
    
    # 7.停用环境
    source deactivate
    
    # 8.更新版本
    conda update python=3.5.2
    
    # 9.查看所有环境
    conda info --envs
    
    # 10.给环境安装其他软件包
    conda install --name my_env35 numpy
    
    # 11.删除环境变量
    conda remove --name my_env --all
    
    # 12.更新 anaconda
    conda update conda
    
    # 13.卸载Anaconda
    conda install anaconda-clean --yes
    rm -rf ~/anaconda3
    vim ~/.bashrc
    
    # 14.更换仓库镜像
    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 --set show_channel_urls yes

                                   

  • 相关阅读:
    CSPS模拟 65
    CSPS模拟 64
    $color$有色图
    CSPS模拟 63
    CSPS模拟 62
    CSPS模拟 61
    CSPS模拟 60
    CSPS模拟 59
    go中单链表
    MYSQL-联合索引
  • 原文地址:https://www.cnblogs.com/zhuminghui/p/10973522.html
Copyright © 2011-2022 走看看