zoukankan      html  css  js  c++  java
  • Anaconda的安装与使用

    1. 安装Anaconda(Command Line)

    1.1 下载

    首先去Anaconda官网查看下载链接,然后通过命令行下载:

    $ wget https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh
    

    1.2 安装

    $ bash Anaconda3-5.0.1-Linux-x86_64.sh
    

    安装过程推荐采用默认配置。

    1.3 配置环境

    为了能在所有命令行自由调用pip、python等工具,需要配置环境:

    # 将anaconda的bin目录加入PATH,根据版本不同,可能是~/anaconda3/bin
    $ echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc
    # 更新bashrc以立即生效
    $ source ~/.bashrc
    

    1.4 更新

    $ conda upgrade --all
    
    

    2 Conda镜像源管理

    清华大学开源软件镜像站中查找anaconda镜像源。使用国内镜像源,软件包下载安装会很快。

    # 添加源
    $ 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
    
    # 查看源
    $ conda config --show-sources
    ==> /home/libbitcoin/.condarc <==
    channels:
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
      - defaults
    show_channel_urls: True
    
    

    配置完以后,会生成配置文件~/.condarc,内容如下:

    $ cat .condarc
    show_channel_urls: true
    channels:
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
      - defaults
    
    

    3. 基本使用

    Conda的环境管理功能允许我们同时安装若干不同版本的Python,并能自由切换。

    3.1 创建新的python环境

    创建一个python环境,指定版本为3.6。

    $ conda create --name python36 python=3.6
    

    3.2 激活指定python环境

    安装好后,使用activate激活python36.

    # for Windows
    $ activate python36
    
    # for Linux & Mac
    $ source activate python36
    
    # 查询当前版本
    $ python --version
    Python 3.6.8 :: Anaconda, Inc.
    

    3.3 退出python环境

    # for Windows
    $ deactivate python36 
    
    # for Linux & Mac
    $ source deactivate python36 
    

    3.4 删除python环境

    $ conda remove --name python36 --all
    

    4 说明

    我们使用conda命令所创建的python环境,其所有文件,包括python解释器和第三方依赖库(通过conda或者pip安装),都位于目录~/anaconda3/envs/下,每个环境对应该目录下的一个子文件夹,有利于隔离与搬移。

    最后说一句,Anaconda的最大优势不在于丰富的库资源,而在于它能创建多个独立的python环境,并在这其间自由的切换。

  • 相关阅读:
    数据库自动重连
    golang slice分割和append copy还是引用
    Unicode和UTF-8的关系
    golang的内置类型map的一些事
    svn sync主从同步学习
    CMake学习笔记
    常用排序总结
    优先队列实现Huffman编码
    linux 下C++查询mysql数据库
    ubuntu下C++连接mysql数据库
  • 原文地址:https://www.cnblogs.com/sword03/p/10561144.html
Copyright © 2011-2022 走看看