很多使用过python的读者都知道,python光使用系统函数库是远远不能满足要求的,有时候我们需要使用第三方函数库与自定义函数库,然而第三方函数库是要自己手动安装的,由于笔者正在学习python,所以就演示一下安装过程,这里只展示windows的安装过程,linux的不再叙述,有兴趣的读者自行百度。
第一步,在python官网上下载第三方函数库httplib2,这里的版本为httplib2-0.9.2,点击下载地址即可下载。
第二步,将刚刚下载的压缩包解压到某个文件夹里,以笔者的为例,结果如下。
第三步,配置系统环境变量,这一步也是最重要的。
1.在搜索窗口中输入编辑系统环境变量,点击选项,弹出如下对话框,点击“环境变量”
出现如下对话框
选中系统变量中的Path(因为笔者已经设置好了,所以可以看到D:python2.7,没设置以前应该是看不到的),点击编辑,出现如下对话框,按照如下图的输入,最后点击确定即可。
备注:这里笔者的python运行环境在D盘的python2.7目录下,所以这样输入,读者要按照自己python所安装实际路径为准
第四步,dos下安装httplib2
1.打开cmd,进入httplib2-0.9.2.zip的解压目录,如下图。
2.安装httplib2,输入python setup.py install(setup.py文件在httplib2解压包中可以看到),看到如下结果就为安装成功
第五步,我们来写一个小的python程序来验证该第三方库函数是否能正常工作,打开python2.7。
>>> import urllib >>> import webbrowser >>> url = 'http://www.163.com' >>> content = urllib.urlopen(url).read() >>> print content
>>> open('163.com.html','w').write(content)
这段程序代码的意思是打开163网站,下载网站的首页,并放到content里面,最后在本地下新建一个html文件163.com,并在该文件中写入content里的内容,并打开查看,结果如下,由于163网站首页html里的内容较多,这里只选取部分内容截图。
<ul class="clearfix"> <li> <a href="http://g.163.com/a?CID=47692&Values=326135876&Redirect=http://hanjia.xdf.cn?utm_source=jituan_Portal_163&utm_medium=CPD&utm_campaign=jituan_163_hanjia_neiyetonglan&utm_term=neiyetonglan&xdf_source_channel_code=d22b6ec5c4f21da483c678731ee44b1f">新东方寒假班报名入口</a> <a href="http://g.163.com/a?CID=47693&Values=576397429&Redirect=http://vip.jjl.cn/?from=netease_home_cg_wzl01">金吉列留学免费评估</a> </li> <li> <a href="http://g.163.com/a?CID=47694&Values=1950097946&Redirect=http://www.jjl.cn/?from=netease_home_cg_wzl02">出国留学新探索</a> <a href="http://g.163.com/a?CID=47695&Values=668102420&Redirect=http://www.cansine.com/zt/170107mt/index.php?hmsr=%E7%BD%91%E6%98%93&hmpl=2017.1.7%E4%BC%9A%E8%AE%AE%E6%8E%A8%E5%B9%BF&hmcu=&hmkw=&hmci=">移民葡萄牙还是希腊?</a> </li> <li> <a href="http://g.163.com/a?CID=47696&Values=3489503382&Redirect=http://www.51liucheng.com/">柳橙网留学免费评估</a> <a href="http://g.163.com/a?CID=47697&Values=2712976931&Redirect=http://www.uibehnd.com/guide.asp">录取不理想!怎么办?</a> </li> </ul> <ul class="clearfix"> <li> <a href="http://g.163.com/a?CID=47698&Values=166813985&Redirect=http://edu.163.com/17/0106/14/CA3SVABM00297VV9.html">上财商学院新年贺词</a> <a href="http://g.163.com/a?CID=47699&Values=363433078&Redirect=http://www.iccn-germany.com/ShowNews.asp?ID=490">以教育之名,移民德国</a> </li> <li> <a href="http://g.163.com/a?CID=47700&Values=1538390836&Redirect=http://www.yflhedu.com/">生态幼儿园项目投资分享</a> <a href="http://g.163.com/a?CID=47701&Values=2174023045&Redirect=http://mp.weixin.qq.com/s/1i8jquBojnLZiimYhAcDyw">平面设计闯关等你来战 </a> </li> <li> <a href="http://g.163.com/a?CID=47702&Values=3937817098&Redirect=https://www.shanbay.com/m/intro/?app=listen">扇贝,知道你在改变</a> <a href="http://g.163.com/a?CID=47703&Values=1985250268&Redirect=http://www.bjdfeicuiedu.com/subject/zt/youxixuexiao/">游戏学院冬季班开课啦</a> </li> </ul> </div> <div ne-role="tab-body" class="hp_textlink1_body clearfix"> <ul class="clearfix"> <li> <a href="http://you.163.com/act/pub/GQKpRh6POE.html?from=web_gg_zhannei_zhanneiwz_0">严选新年好货低至0元</a> <a href="http://piao.163.com/movie/47960.html?from=zheye">英雄猪少年拯救世界</a> </li> <li> <script type="text/template" ne-repeat="t in textlink"> <%if(__i < 2){%> <a href="<%=t.link%>"><%=t.title%></a> <%}%> </script> </li> </ul> <!-- 右侧6条 --> <ul class="clearfix"> <script type="text/template" ne-foreach="t in textlink"> <%if(__i > 1){%> <%if(__i % 2 == 0){%> <li> <%}%> <a href="<%=t.link%>"><%=t.title%></a> <%if(__i % 2 != 0){%> </li> <%}%> <%}%> </script> </ul> </div> </div> <span class="channel_ad_text_2016">广告</span> </div></div> <!-- 首屏 --> <div class="cm_area ns_area_first"> <div class="col_lm"> <!-- 左 --> <div class="col_l"> <!-- 焦点图 --> <div ne-module="modules/slide/slide.js" class="mod_slide_newspic"> <div ne-module="slide" class="cm_mod_slide mod_idx_focus" ne-state="slideMethod:left;events=mouseover;interval=5000;loop:1"> <div ne-role="slide-body" class="focus_body" ne-swipe="state.onswipe($event)"> <ul ne-role="slide-scroll"> <li class="current" ne-role="slide-page"> <div class="cm_bigimg"> <a href="http://news.163.com/photoview/00AP0001/2226551.html" title="郑州现1500斤“猪王” 体长2.1米能当牛骑" class="photo"> <img src="http://cms-bucket.nosdn.127.net/0c242f38ee074e8788a586a2d27521fc20170109080500.jpeg?imageView&thumbnail=380y187&quality=85" alt="郑州现1500斤“猪王” 体长2.1米能当牛骑"/> </a> <span class="bg"></span> <h3><a href="http://news.163.com/photoview/00AP0001/2226551.html">郑州现1500斤“猪王” 体长2.1米能当牛骑</a></h3> </div> <div class="smallimg"> <div class="pic"> <a href="http://news.163.com/photoview/00AO0001/2226556.html" title="伊朗前总统因心脏病去世" class="photo"> <img src="http://cms-bucket.nosdn.127.net/1642d2de246142ef9b52606e9783bc1720170109075937.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="伊朗前总统因心脏病去世"/> <span class="bg"></span> <h3>伊朗前总统因心脏病去世</h3> </a> <a href="http://ent.163.com/photoview/00AJ0003/622788.html#p=CAARLAUB00AJ0003" title="会玩!showgirl秀美腿豪乳" class="photo"> <img src="http://img3.cache.netease.com/ent/2017/1/9/20170109083111df684.jpg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="会玩!showgirl秀美腿豪乳"/> <span class="bg"></span> <h3>会玩!showgirl秀美腿豪乳</h3> </a> </div> <div class="pic"> <a href="http://news.163.com/photoview/00AP0001/2226555.html" title="老农守护悬崖千年佛像30年" class="photo"> <img src="http://cms-bucket.nosdn.127.net/772d60a5508d451aad6c01018acda93720170109080740.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="老农守护悬崖千年佛像30年"/> <span class="bg"></span> <h3>老农守护悬崖千年佛像30年</h3> </a> <a href="http://sports.163.com/photoview/28F90005/152040.html" title="冉莹颖花式秀傲人上围" class="photo"> <img src="http://cms-bucket.nosdn.127.net/ef044922bb4c4a1e9033ebc922f9233120170109072256.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="冉莹颖花式秀傲人上围"/> <span class="bg"></span> <h3>冉莹颖花式秀傲人上围</h3> </a> </div> </div> </li> <li ne-role="slide-page"> <div class="cm_bigimg"> <a href="http://sports.163.com/photoview/1TSK0005/152060.html" title="李宁师弟恋洋美女被开除 入籍瑞士奥运夺金" class="photo"> <img src="http://cms-bucket.nosdn.127.net/c0bf86a6d505422ab16ac71b7eb5dc0f20170109071730.jpeg?imageView&thumbnail=380y187&quality=85" alt="李宁师弟恋洋美女被开除 入籍瑞士奥运夺金"/> </a> <span class="bg"></span> <h3><a href="http://sports.163.com/photoview/1TSK0005/152060.html">李宁师弟恋洋美女被开除 入籍瑞士奥运夺金</a></h3> </div> <div class="smallimg"> <div class="pic"> <a href="http://sports.163.com/photoview/5GUP0005/152038.html" title="1米88小将成CBA扣篮王" class="photo"> <img src="http://cms-bucket.nosdn.127.net/5cee629b776d437b8b49333d2afda5a020170109085105.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="1米88小将成CBA扣篮王"/> <span class="bg"></span> <h3>1米88小将成CBA扣篮王</h3> </a> <a href="http://lady.163.com/photoview/5SJC0026/105987.html" title="张天爱的发型都好美" class="photo"> <img src="http://cms-bucket.nosdn.127.net/fac3710e0b854673a78707c061e9185f20170109080638.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="张天爱的发型都好美"/> <span class="bg"></span> <h3>张天爱的发型都好美</h3> </a> </div> <div class="pic"> <a href="http://ent.163.com/photoview/00AJ0003/622794.html#p=CAATB2LQ00AJ0003" title="苏菲·玛索穿深V红裙吐舌" class="photo"> <img src="http://img1.cache.netease.com/ent/2017/1/9/20170109083417ddad8.jpg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="苏菲·玛索穿深V红裙吐舌"/> <span class="bg"></span> <h3>苏菲·玛索穿深V红裙吐舌</h3> </a> <a href="http://tech.163.com/photoview/0AI20009/14103.html#p=CA9VHGSV0AI20009" title="外媒图集:风筝混入候鸟群" class="photo"> <img src="http://cms-bucket.nosdn.127.net/bf182e1d526d4928a14d36a61c7c6e7720170109090801.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="外媒图集:风筝混入候鸟群"/> <span class="bg"></span> <h3>外媒图集:风筝混入候鸟群</h3> </a> </div> </div> </li> <li ne-role="slide-page"> <div class="cm_bigimg"> <a href="http://ent.163.com/photoview/00AJ0003/622790.html#p=CAARUU3K00AJ0003&from=tj_review" title="又亮胸器!柳岩俯身灿笑秀美胸 性感撩人" class="photo"> <img src="http://img6.cache.netease.com/ent/2017/1/9/201701090827484f61d.jpg?imageView&thumbnail=380y187&quality=85" alt="又亮胸器!柳岩俯身灿笑秀美胸 性感撩人"/> </a> <span class="bg"></span> <h3><a href="http://ent.163.com/photoview/00AJ0003/622790.html#p=CAARUU3K00AJ0003&from=tj_review">又亮胸器!柳岩俯身灿笑秀美胸 性感撩人</a></h3> </div> <div class="smallimg"> <div class="pic"> <a href="http://news.163.com/photoview/00AO0001/2226565.html" title="民众领奥巴马告别演讲门票" class="photo"> <img src="http://cms-bucket.nosdn.127.net/2783e3f338b34bdb8638c463c6067f2b20170109080058.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="民众领奥巴马告别演讲门票"/> <span class="bg"></span> <h3>民众领奥巴马告别演讲门票</h3> </a> <a href="http://news.163.com/photoview/00AO0001/2226609.html" title="法巴士失控滑出公路致死伤" class="photo"> <img src="http://cms-bucket.nosdn.127.net/999b6ccf5c2242f9a2c0bed25608f47720170109095152.jpeg?imageView&thumbnail=185y116&quality=85" width="185" height="116" alt="法巴士失控滑出公路致死伤"/> <span class="bg"></span> <h3>法巴士失控滑出公路致死伤</h3> </a> </div> <div class="pic">
回到python2.7的安装目录下,发现多了一个叫163.com的html文件
点击查看
发现就是163网站的首页,说明httplib2安装成功。