Python交互式编程,,Python之ipy


Python之ipython、notebook、matplotlib安装使用

交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编写代码。

linux上你只需要在命令行中输入 Python 命令即可启动交互式编程

Window上在安装Python时已经已经安装了默认的交互式编程客户端

备注:>中文编码#!/usr/bin/python#-*-coding:UTF-8-*-

以下进行逐步安装配置

python3.5.2,ipython5.1.0,jupyternotebook,matplotlib

1、安装python3.5

具体安装请参考官方文档。安装程序时注意勾选配置环境变量。https://www.python.org/downloads/windows/

2、升级pip

python-mpipinstall--upgradepip

3、使用pip安装ipython

pip.exeinstallipython

交互模式效果如下

D:\tools>ipythonPython3.5.2(v3.5.2:4def2a2901a5,Jun252016,22:01:18)[MSCv.190032bit(Intel)]Type"copyright","credits"or"license"formoreinformation.IPython5.1.0--AnenhancedInteractivePython.?->IntroductionandoverviewofIPython‘sfeatures.%quickref->Quickreference.help->Python‘sownhelpsystem.object?->Detailsabout‘object‘,use‘object??‘forextradetails.In[1]:print(‘helloworld!‘)helloworld!In[2]:a=[‘Windows‘,‘10‘,‘Python‘,‘3.5.2‘,‘ipython‘,‘jupyternotebook‘]In[3]:aOut[3]:[‘Windows‘,‘10‘,‘Python‘,‘3.5.2‘,‘ipython‘,‘jupyternotebook‘]In[4]:foriina:...:print(i)...:Windows10Python3.5.2ipythonjupyternotebookIn[5]:

4、使用pip安装notebook

pipinstallnotebook

提示已成功安装的包和版本

Installingcollectedpackages:jupyter-core,MarkupSafe,jinja2,jsonschema,nbformat,entrypoints,mistune,nbconvert,tornado,pyzmq,jupyter-client,ipykernel,notebookRunningsetup.pyinstallforMarkupSafe...doneSuccessfullyinstalledMarkupSafe-0.23entrypoints-0.2.2ipykernel-4.5.0jinja2-2.8jsonschema-2.5.1jupyter-client-4.4.0jupyter-core-4.2.0mistune-0.7.3nbconvert-4.2.0nbformat-4.1.0notebook-4.2.3pyzmq-15.4.0tornado-4.4.2

在工作目录下启动notebook

jupyternotebookD:\tools>jupyternotebook[W07:44:23.940NotebookApp]Widgetsareunavailable.Pleaseinstallwidgetsnbextensionoripywidgets4.0[I07:44:23.955NotebookApp]Theport8888isalreadyinuse,tryinganotherport.[I07:44:24.143NotebookApp]Servingnotebooksfromlocaldirectory:D:\tools[I07:44:24.143NotebookApp]0activekernels[I07:44:24.143NotebookApp]TheJupyterNotebookisrunningat:http://localhost:8889/[I07:44:24.143NotebookApp]UseControl-Ctostopthisserverandshutdownallkernels(twicetoskipconfirmation).

web

技术分享

5、安装画图工具 matplotlib

pipinstallmatplotlibpipinstallmatplotlib--upgrade

结果提示

Installingcollectedpackages:cycler,pytz,pyparsing,numpy,python-dateutil,matplotlibSuccessfullyinstalledcycler-0.10.0matplotlib-1.5.3numpy-1.11.2pyparsing-2.1.10python-dateutil-2.5.3pytz-2016.7

6、测试

b图像测试代码来源:

https://my.oschina.net/bery/blog/203595

importnumpyasnpimportmatplotlib.pyplotaspltN=5menMeans=(20,35,30,35,27)menStd=(2,3,4,1,2)ind=np.arange(N)#thexlocationsforthegroupswidth=0.35#thewidthofthebarsfig,ax=plt.subplots()rects1=ax.bar(ind,menMeans,width,color=‘r‘,yerr=menStd)womenMeans=(25,32,34,20,25)womenStd=(3,5,2,3,3)rects2=ax.bar(ind+width,womenMeans,width,color=‘y‘,yerr=womenStd)#addsomeax.set_ylabel(‘Scores‘)ax.set_title(‘Scoresbygroupandgender‘)ax.set_xticks(ind+width)ax.set_xticklabels((‘G1‘,‘G2‘,‘G3‘,‘G4‘,‘G5‘))ax.legend((rects1[0],rects2[0]),(‘Men‘,‘Women‘))defautolabel(rects):#attachsometextlabelsforrectinrects:height=rect.get_height()ax.text(rect.get_x()+rect.get_width()/2.,1.05*height,‘%d‘%int(height),ha=‘center‘,va=‘bottom‘)autolabel(rects1)autolabel(rects2)plt.show()

技术分享

%matplotlibinlineimportnumpyasnpimportmatplotlib.pyplotaspltx=np.arange(9)y=np.sin(x)plt.plot(x,y)plt.show()

技术分享



本文出自 “随心” 博客,请务必保留此出处http://bennychen.blog.51cto.com/6323894/1860258

Python交互式编程

评论关闭