Wenchaoz

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

为了安装Matplotlib 百度了一大堆,也下载了一大堆安装包,结果还是报错ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。

后来直接从官网看怎么安装http://matplotlib.org/users/installing.html

For standard Python installations you will also need to install compatible versions of setuptoolsnumpypython-dateutilpytzpyparsing, and cycler in addition to matplotlib.

然后发现好像可以直接用Powershell利用内置的pip(python包管理工具,详情可参见https://pip.pypa.io/en/stable/)

首先是更新一下pip (确保pip能使用)

然后将setuptoolsnumpypython-dateutilpytzpyparsingcycler,matplotlib分别代替最后的pip并运行

PS C:\Users\wenchaoz> python -m pip install --upgrade pip
Collecting pip
  Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 315kB/s
Installing collected packages: pip
  Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
Successfully installed pip-8.1.2
PS C:\Users\wenchaoz> python -m pip install --upgrade numpy
Collecting numpy
  Downloading numpy-1.11.1-cp27-none-win_amd64.whl (7.4MB)
    100% |████████████████████████████████| 7.4MB 138kB/s
Installing collected packages: numpy
  Found existing installation: numpy 1.9.2
    DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future
version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling numpy-1.9.2:
      Successfully uninstalled numpy-1.9.2
Successfully installed numpy-1.11.1
PS C:\Users\wenchaoz> python -m pip install --upgrade pytz
Collecting pytz
  Downloading pytz-2016.6.1-py2.py3-none-any.whl (481kB)
    100% |████████████████████████████████| 481kB 1.2MB/s
Installing collected packages: pytz
Successfully installed pytz-2016.6.1
PS C:\Users\wenchaoz> python -m pip install --upgrade pyparsing
Collecting pyparsing
  Downloading pyparsing-2.1.5-py2.py3-none-any.whl (42kB)
    100% |████████████████████████████████| 51kB 122kB/s
Installing collected packages: pyparsing
Successfully installed pyparsing-2.1.5
PS C:\Users\wenchaoz> python -m pip install --upgrade cycler
Collecting cycler
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Requirement already up-to-date: six in c:\python27\lib\site-packages (from cycler)
Installing collected packages: cycler
Successfully installed cycler-0.10.0
PS C:\Users\wenchaoz> python -m pip install --upgrade matplotlib
Collecting matplotlib
  Downloading matplotlib-1.5.1-cp27-none-win_amd64.whl (6.1MB)
    100% |████████████████████████████████| 6.1MB 167kB/s
Requirement already up-to-date: cycler in c:\python27\lib\site-packages (from matplotlib)
Requirement already up-to-date: pytz in c:\python27\lib\site-packages (from matplotlib)
Requirement already up-to-date: pyparsing!=2.0.4,>=1.5.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already up-to-date: numpy>=1.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already up-to-date: python-dateutil in c:\python27\lib\site-packages (from matplotlib)
Requirement already up-to-date: six in c:\python27\lib\site-packages (from cycler->matplotlib)
Installing collected packages: matplotlib
  Found existing installation: matplotlib 1.5.0
    Uninstalling matplotlib-1.5.0:
      Successfully uninstalled matplotlib-1.5.0
Successfully installed matplotlib-1.5.1

 

网上找的测试代码:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.show()

得到下图的话,恭喜你,ok了

 

posted on 2016-07-17 21:00  Wenchaoz  阅读(3777)  评论(0编辑  收藏  举报