• 通过Anaconda配置Windows 10上Python环境


    介绍

    Anaconda是啥?看官网
    为什么使用Anaconda?

    1. Anaconda已经预安装很多常用包,特别是数据分析相关的,开箱即用;
    2. Anaconda和常用的Pycharm、VS Code做了很好的适配,开箱即用;
    3. Jupyter Notebook已安装,开箱即用。

    下载

    不要通过官网下载,踩过坑了,国内下载安装存在网络问题。
    推荐Anaconda清华源,下文用tuna代称清华源。访问这个地址,选择最新版本安装。

    安装

    按照推荐选项安装即可,for current user。

    安装后必做

    替换Python源

    由于国内访问Python源现在也出现了问题,所以最好修改为tuna源。
    推荐:

    • 打开Anaconda Prompt(anaconda3),然后运行pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    • 如果是临时使用的话,使用命令pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <some-package>
      备用,其实和上面的方法结果相同。
    • 修改Python源,在C:Users<username>下添加 pippip.ini,内容如下。
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 修改conda源,在C:Usersusername下添加.condarc文件
    channels:
      - defaults
    show_channel_urls: true
    channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
    default_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/pkgs/r
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
    custom_channels:
      conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
    ssl_verify: true
    

    新建虚拟环境

    如果要管理不同的Python版本,比如Python2.7/Python3.6,就要通过虚拟环境。详细可以参考官方文档
    打开Anaconda Prompt(anaconda3)按下面命令说明操作。

    # 查看conda版本
    conda -V
    # 创建一个名为myenv的python3.6的虚拟环境
    conda create -n myenv python=3.6
    # 查看已有环境,这个环境一般在C:Users<username>anaconda3envs目录下
    conda env list
    # 激活环境
    conda activate myenv
    # 退出环境
    conda deactivate 
    

    Anaconda Navigator

    安装之后我们会得到一个Anaconda Navigator,简单介绍一下常用的。

    • 提供了图形化的虚拟环境以及已安装包的视图。
    • Notebook,Jupyter Notebook,写笔记用。
    • CMD.exe Prompt,启动conda环境的cmd程序。
    • Powershell Prompt,如果你会Powershell的话,会比CMD更好用。
    • VS Code,如果你安装了VS Code的话,会存在这个选项。
    • Spyder,适合数据工程师的IDE,一般用不上。
    • 其他常用的就是python相关官方文档的快速访问方式,不赘述。

    使用

    打开Pycharm或者VS Code,在Python解释器选择界面就可以看到conda所创建的环境。
    开箱即用,非常简单。
    如果需要试用git bash替代anaconda prompt,https://stackoverflow.com/questions/54501167/anaconda-and-git-bash-in-windows-conda-command-not-found
    echo ". /c/Anaconda3/etc/profile.d/conda.sh" >> ~/.profile

  • 相关阅读:
    标志寄存器和跳转指令
    js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版【转】
    关于mysql的级联删除(之前好多人咨询过我)
    用DIV画个漂亮的Table,根本看不出是div画的
    最简单的Ajax局部提交整体form,无刷新页面
    themeleaf中使用javascript时,字符“&&”的转义问题。
    Mysql 进行sequence的新建,同时建立计划每日重置。
    动态给H5页面绑定数据,基本万能无错误!
    手风琴效果简单实现,修改bootstrap内部事件接口并且自由定义。
    JQuery实现追加表格,不使用拼接html方式
  • 原文地址:https://www.cnblogs.com/jamesnpu/p/13595861.html
Copyright © 2020-2023  润新知