win7下安装Python +matplotlib

来源:互联网 发布:mac翻墙用什么软件好 编辑:程序博客网 时间:2024/05/16 07:55

终于安装好了Python +matplotlib特此记录下。感谢以下几个文字的作者给我的帮助,同时大家也可以参考这几个作者的方法:

1、http://www.open-open.com/lib/view/open1393488232380.html

2、http://blog.csdn.net/yang6464158/article/details/18546871#comments

3、http://blog.sina.com.cn/s/blog_6fb8aa0d0101qtt9.html

4、http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html

5、http://jingyan.baidu.com/article/fdffd1f8390029f3e98ca102.html

同时附上安装程序下载的地址http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

一、安装python

首先先安装好python 因为3.X版本很多库不兼容,所以还是使用2.7的。python下载地址https://www.python.org/download/我用的是64位的。整体而言,整个安装过程,如果用64的包就所有的包都需要用64的,不然会有问题。

二、安装matplotlib(在安装的时候,如果出现Python version 2.7 required, which was not found in the registry这样的问题,请参见http://blog.csdn.net/bush2582/article/details/39928049

安装matplotlib最好选择1.3.0.版本的,不然会出现一个ImportError: six 1.3 or later is required; you have 1.2.0这样的问题。 下载之后,点击安装即可。

三、安装dateutil,pyparsing,scipy

这三个库,都是在运行的时候需要的,缺失不同的库,会导致不同的错误:
1、dateutil:
raise ImportError("matplotlib requiresdateutil")
ImportError: matplotlib requires dateutil
2、pyparsing:
raise ImportError("matplotlib requirespyparsing")
ImportError: matplotlib requires pyparsing
3、scipy:

No module name six

在安装完毕scipy之后把C:\Python27\Lib\site-packages\scipy\lib中的six.py six.pyc six.pyo三个文件拷贝到C:\Python27\Lib\site-packages目录下。

四、安装NumPy

安装NumPy的时候需要特别注意,如果你前面的包都是64的请安装64位的NumPy不然会出现例如如下的错误:

Traceback (most recent call last):

File "D:\works\JetBrains\python\simplePref\test.py", line 5, in <module>

import matplotlib.pyplot as plt; plt.rcdefaults()

File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 156, in <module>

from matplotlib.cbook import is_string_like

File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 28, in <module>

import numpy as np

File "C:\Python27\lib\site-packages\numpy\__init__.py", line 153, in <module>

from . import add_newdocs

File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>

from numpy.lib import add_newdoc

File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>

from .type_check import *

File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>

import numpy.core.numeric as _nx

File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 6, in <module>

from . import multiarray

ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。

同时64的NumPy包的名字是numpy-MKL-1.8.1.win-amd64-py2.7.exe,请注意。

五、安装完毕测试

安装好了之后,可以填入如下的测试程序(测试程序源于http://www.open-open.com/lib/view/open1393488232380.html)结果如图:
[python] view plaincopy在CODE上查看代码片派生到我的代码片
  1. import numpy as np  
  2. import matplotlib.pyplot as plt  
  3.    
  4. N = 5  
  5. menMeans = (2035303527)  
  6. menStd =   (23412)  
  7.    
  8. ind = np.arange(N)  # the x locations for the groups  
  9. width = 0.35       # the width of the bars  
  10.    
  11. fig, ax = plt.subplots()  
  12. rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)  
  13.    
  14. womenMeans = (2532342025)  
  15. womenStd =   (35233)  
  16. rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)  
  17.    
  18. # add some  
  19. ax.set_ylabel('Scores')  
  20. ax.set_title('Scores by group and gender')  
  21. ax.set_xticks(ind+width)  
  22. ax.set_xticklabels( ('G1''G2''G3''G4''G5') )  
  23.    
  24. ax.legend( (rects1[0], rects2[0]), ('Men''Women') )  
  25.    
  26. def autolabel(rects):  
  27.     # attach some text labels  
  28.     for rect in rects:  
  29.         height = rect.get_height()  
  30.         ax.text(rect.get_x()+rect.get_width()/2.1.05*height, '%d'%int(height),  
  31.                 ha='center', va='bottom')  
  32.    
  33. autolabel(rects1)  
  34. autolabel(rects2)  
  35.    
  36. plt.show()  
0 0