zoukankan      html  css  js  c++  java
  • conda 使用清华大学开源软件镜像

    conda 使用清华大学开源软件镜像

    Anaconda的安装步骤不在本文的讨论中,我们主要是学习一下如何配置conda的镜像,以及一些问题的解决过程

    配置镜像

    在conda安装好之后,默认的镜像是官方的,由于官网的镜像在境外,我们使用国内的镜像能够加快访问的速度。这里我选择了清华的的镜像。镜像的地址如下:点我进入tuna

    在命令行中运行

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --set show_channel_urls yes

    enter description here

    enter description here

    由于我已经配置好了,就不能回车配置,上面的两条语句,直接执行就可以,如何配置了,还执行上面的语句就会报下面的错。

    Warning: 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' already in 'channels' list, moving to the top

    enter description here

    上面两部做完之后,前往当前用户的目录下,查看一个名为.condarc为文件,看是不是像下面的内容一样

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

    enter description here

    注意:配置完成之后,要关闭控制台再重新打开控制台,这样新配置的文件才会被加载进来

    创建conda环境

    上面的步骤完成之后,如果我们想使用conda install pip来升级pip的话,直接上来就是这句命令,则会出现下面的情况

    C:UsersNEIL-PC>conda install pip
    Fetching package metadata ...........
    Solving package specifications: ..........
    
    Package plan for installation in environment C:Program FilesAnaconda2:
    
    The following packages will be downloaded:
    
        package                    |            build
        ---------------------------|-----------------
        conda-env-2.6.0            |                0          498 B  https://mirror
        conda-4.2.13               |           py27_0         455 KB  https://mirror
        pip-9.0.1                  |           py27_1         1.6 MB  https://mirror
        ------------------------------------------------------------
                                               Total:         2.1 MB
    
    The following NEW packages will be INSTALLED:
    
        conda-env: 2.6.0-0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/f
    
    The following packages will be UPDATED:
    
        conda:     4.2.9-py27_0 defaults
        pip:       8.1.2-py27_0 defaults
    
    CondaIOError: IO error: Missing write permissions in: C:Program FilesAnaconda2
    #
    # You don't appear to have the necessary permissions to install packages
    # into the install area 'C:Program FilesAnaconda2'.
    # However you can clone this environment into your home directory and
    # then make changes to it.
    # This may be done using the command:
    #
    # $ conda create -n my_root --clone=C:Program FilesAnaconda2

    最重要的提示在最后
    enter description here

    ok,那我们就按照提示来创建环境

    conda create -n my_root --clone=C:Program FilesAnaconda2

    enter description here

    后面,我怀疑是不是my_root要显示的制定为我的用户文件夹,继续尝试

    conda create -n C:UsersNEIL-PC --clone=C:Program FilesAnaconda2

    enter description here

    然后,我大概猜测了一些,怀疑是--clone=C:Program FilesAnaconda2这句是多余的,那么继续尝试

    conda create -n my_root

    回车,看到了下面的结果

    C:UsersNEIL-PC>conda create -n my_root
    Fetching package metadata ...........
    .Solving package specifications: .
    Package plan for installation in environment C:UsersNEIL-PC.condaenvsmy_roo
    t:
    
    The following empty environments will be CREATED:
    
    C:UsersNEIL-PC.condaenvsmy_root
    
    Proceed ([y]/n)? y
    
    #
    # To activate this environment, use:
    # > activate my_root
    #
    # To deactivate this environment, use:
    # > deactivate my_root
    #
    # * for power-users using bash, you must source
    #
    

    最重要的还是最后的提示部分

    enter description here

    根据上图中的提示,我们可以发现conda通过下面两个命令来启用和禁用某个环境
    - activate my_root
    - deactivate my_root

    那OK,按照提示,我们使用

    activate my_root

    enter description here

    根据上图的运行结果,我们可以大胆的猜测,my_root并不是一个变量(指向系统文件的变量,而是一样环境的名称),事实也是这样的,我们可以在用户目录中查看所有的conda环境。

    cd .conda
    cd envs
    dir

    enter description here

    从上图中,我们可以看到my_root的文件夹,为了进一步看到里面的东西,大家可以尝试打开my_root文件夹下的内容简单的瞅一下。

    直接conda install pip

    经过上面的步骤,我们已经配置好了conda的环境,那么我们再来尝试一下升级pip
    同上,我们使用conda来升级pip的命令如下

    conda install pip

    TNND,又出错了

    C:UsersNEIL-PC>conda install pip
    Fetching package metadata ...........
    Solving package specifications: ..........
    
    Package plan for installation in environment C:Program FilesAnaconda2:
    
    The following packages will be downloaded:
    
        package                    |            build
        ---------------------------|-----------------
        conda-env-2.6.0            |                0          498 B  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
        conda-4.2.13               |           py27_0         455 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
        pip-9.0.1                  |           py27_1         1.6 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
        ------------------------------------------------------------
                                               Total:         2.1 MB
    
    The following NEW packages will be INSTALLED:
    
        conda-env: 2.6.0-0      https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free (copy)
    
    The following packages will be UPDATED:
    
        conda:     4.2.9-py27_0 defaults                                                --> 4.2.13-py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free (copy)
        pip:       8.1.2-py27_0 defaults                                                --> 9.0.1-py27_1  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free (copy)
    
    CondaIOError: IO error: Missing write permissions in: C:Program FilesAnaconda2
    #
    # You don't appear to have the necessary permissions to install packages
    # into the install area 'C:Program FilesAnaconda2'.
    # However you can clone this environment into your home directory and
    # then make changes to it.
    # This may be done using the command:
    #
    # $ conda create -n my_root --clone=C:Program FilesAnaconda2
    

    还是上面的错误,经过仔细查看报错的原因,发现了一句很重要的内容

    enter description here

    从上图中,我们发现conda是安装在C盘中的,可能是缺少写文件的权限,那ok,我们用管理员身份打开控制台,再运行conda install pip

    enter description here

    enter description here

    可以看到,已经安装完成,下面我们再看看能否用pip来安装软件包

    enter description here

    可以看到这里pip的速度很慢,pip也是可以配置镜像的,一般都是用豆瓣的镜像,具体的方法,大家可以百度一下。
    速度太慢,还是直接使用conda来安装吧

    enter description here

    enter description here

    为什么我们一上来就要升级pip

    一般来说,我们按照好conda之后,pip的版本比较低,例如我的就是

    C:UsersNEIL-PC>pip -V
    pip 8.1.2 from C:Program FilesAnaconda2libsite-packages (python 2.7)

    但是,如果这时候,你想升级某个包就会报错了,会提示你要升级pip

    $ pip install scikit-learn
    Requirement already satisfied (use --upgrade to upgrade): scikit-learn in c:program filesanaconda2libsite-packages
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    

    enter description here

    虽然提示中是可以用下面这条命令来升级pip,但是一般情况下,都是不能升级 pip的,所以,我们还是用conda install pip来升级pip到最新的版本,而且由于我们使用的国内的镜像,速度回很快哒。

    python -m pip install --upgrade pip
  • 相关阅读:
    nodeclub 学习记录
    读mongoose api 记录
    sublime 插件 和free 注册码
    mongodb 基本语法
    安装 adobe flash player
    nginx 安装
    压缩 解压文件
    async 异步流程控制规则
    a标签# 和javascript:;的区别
    获取url 参数
  • 原文地址:https://www.cnblogs.com/shugen/p/6862984.html
Copyright © 2011-2022 走看看