win7下安装matplotlib+six+pysparsing

来源:互联网 发布:mysql 查询总数和分页 编辑:程序博客网 时间:2024/05/17 02:03

一、安装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 dateutil2、pyparsing:raise ImportError("matplotlib requirespyparsing")ImportError: matplotlib requires pyparsing3、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)结果如图:
import numpy as npimport matplotlib.pyplot as plt N = 5menMeans = (20, 35, 30, 35, 27)menStd =   (2, 3, 4, 1, 2) ind = np.arange(N)  # the x locations for the groupswidth = 0.35       # the width of the bars fig, 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) # add someax.set_ylabel('Scores')ax.set_title('Scores by group and gender')ax.set_xticks(ind+width)ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') ) ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') ) def autolabel(rects):    # attach some text labels    for rect in rects:        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()
0 0
原创粉丝点击