系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 脚本中心 > python > 详细页面

通过Anaconda配置Windows 10上Python开发环境

时间:2020-09-01来源:www.pcxitongcheng.com作者:电脑系统城

介绍

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>\下添加 pip\pip.ini,内容如下。
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  • 修改conda源,在C:\Users\username\下添加.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>\anaconda3\envs目录下
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所创建的环境,选一个自己需要的即可。开箱即用,非常简单。

分享到:

相关信息

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载