首页 > 代码库 > Python库 - import matplotlib.pyplot as plt 报错问题

Python库 - import matplotlib.pyplot as plt 报错问题

1、先设置好环境变量
在path变量中设置好以下路径:
C:\Python27\Scripts
C:\Python27
 
2、由于matplotlib依赖dateutil和pyparsing,所以需要安装dateutil
而我们dateutil使用easy_install命令来安装,
但是C:\Python27\Scripts目录下默认没有easy_install.exe
(下面两个地址,下载的是whl文件,需要用pip命令来安装的,但没尝试)
http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing
可以看到Matplotlib, a 2D plotting library.
Requires numpy, dateutil, pytz, pyparsing, cycler, setuptools, and optionally pillow, pycairo, tornado, wxpython, pyside, pyqt4, ghostscript, miktex, ffmpeg, mencoder, avconv, or imagemagick.
所以上面这些包肯定是都需要有的,如果没有遇到问题,可能是因为代码中没有引用这些包而已;或者已经安装了。
 
3、安装easy_install.exe
https://pypi.python.org/pypi/setuptools
找到ez_setup.py文件,下载到本地
在cmd窗口下面,输入:
Python E:\iso\VisualStudio2010\ez_setup.py
成功后,C:\Python27\Scripts\目录下会多了easy_install.exe
 
4、使用easy_install.exe安装dateutil和pyparsing。。
反正根据提示,缺啥就用easy_install安装啥,这个easy_install是按照关键字来搜索安装包的。
easy_install python-dateutil
easy_install pyparsing
easy_install pip
 
4-2、不要使用easy-install安装了,只是用easy_install安装pip就好了
然后使用pip来安装dateutil,pyparsing,matplotlib,pandas,numpy,scipy等的whl
 
5、把路径如:C:\Python27\Lib\site-packages\scipy\lib中的six.py six.pyc six.pyo三个文件拷贝到C:\Python27\Lib\site-packages目录下。
 
另外,这些包貌似都可以下载安装包文件,但是我没有尝试
https://pypi.python.org/pypi/python-dateutil/1.4.1
http://www.pythonhosted.org/six/
http://pyparsing.wikispaces.com/Download+and+Installation
 
6、使用whl来安装各种包
在下面页面下载所对应的32bit或者64bit,区分python2.7还是python3的
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
matplotlib-1.5.2-cp27-cp27m-win_amd64
numpy-1.11.1+mkl-cp27-cp27m-win_amd64.whl
pandas-0.18.1-cp27-cp27m-win_amd64.whl
scipy-0.17.1-cp27-cp27m-win_amd64.whl
把上面这些需要的whl放到python的scripts目录下,然后用下面的命令来安装即可
c:\Python27-x64\Scripts>pip install pandas-0.18.1-cp27-cp27m-win_amd64.whl

Python库 - import matplotlib.pyplot as plt 报错问题