前言
因为研究需要,一直想学习一下Python语言。现在有时间,就针对于Windows 搭建Python开发环境,并做记录。关于Python的种种介绍,网络上已经很多了,这里只提供完整的Windows环境下的安装过程。
Python 下载
Python官网:https://www.python.org/
Python版本选择,Python是区分32位和64位操作系统的,这里选择64位,安装执行程序:
Download Windows x86-64 web-based installer (网络安装版,需联网)
Download Windows x86-64 executable installer (本地安装,可执行程序)
Download Windows x86-64 embeddable zip file (嵌入式版本,可以集成到其它应用中)
提示:考虑到集成开发环境的搭建,如果使用VS或Eclipse IDE,版本又不是最新版时,安装Python时就不要选择最新版(最新版Python往往需要较新版本的IDE支持)。
Python 安装
(1)
(2)
(3)提示
刚开始想安装3.5的,但出现未知错误,就换成3.4了,Python安装比较简单,按照安装向导就可以安装成功了。
测试
cmd
经过以上测试,Python环境搭建结束了。下面就开始搭建集成开发环境(也可以在上面的命令行里开发,想想就让人抓狂),VS 是笔者使用多年的开发环境,下一小节将在VS2013 平台讲解如何搭建Python开发环境。
IDE搭建
(1)安装VS2013(略),也可以安装VS2010,VS2012,VS2015根据自己的版本选择不同插件。
(2)插件下载安装
官网连接:https://pytools.codeplex.com/wikipage?title=PTVS%20Installation
版本选择:
双击安装
(3)添加环境,工具->选项
(4)新建Python项目(Python Application)
(5)测试
print ('Hello World')
如果有中文,会出现如下提示
解决方法:文件->高级保存选项,国标改成UTF-8即可
安装第三方工具包——matplotlib
这里以matplotlib安装为例。选择pip搜索matplotlib进行安装。
测试
import numpy as np
import matplotlib.pyplot as plt
men_means, men_std = (20, 35, 30, 35, 27), (2, 3, 4, 1, 2)
women_means, women_std = (25, 32, 34, 20, 25), (3, 5, 2, 3, 3)
ind = np.arange(len(men_means)) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, men_means, width, yerr=men_std,
color='SkyBlue', label='Men')
rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,
color='IndianRed', label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend()
def autolabel(rects, xpos='center'):
"""
Attach a text label above each bar in *rects*, displaying its height.
*xpos* indicates which side to place the text w.r.t. the center of
the bar. It can be one of the following {'center', 'right', 'left'}.
"""
xpos = xpos.lower() # normalize the case of the parameter
ha = {'center': 'center', 'right': 'left', 'left': 'right'}
offset = {'center': 0.5, 'right': 0.57, 'left': 0.43} # x_txt = x + w*off
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()*offset[xpos], 1.01*height,
'{}'.format(height), ha=ha[xpos], va='bottom')
autolabel(rects1, "left")
autolabel(rects2, "right")
plt.show()
结束
至此,Windows下 以VS2013为IDE的Python开发环境就搭建结束了。