python - 无法让 matplotlib 使用简单绘图的代码

标签 python python-2.7 matplotlib pip setuptools

<分区>

我尝试使用 pip install matplotlib 安装 matplotlib,它重新调整了以下错误。作为引用,我使用的是 Windows 7。

Removing temporary dir c:\users\user\appdata\local\temp\pip_build_RTRA...
Command C:\python27\python.exe -c "import setuptools;__file__='c:\\users\\user\\appdata\\local\\temp\\pip_build_USER\\matplotlib\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\user\appdata\local\temp\pip-yplfpm-record\install-record.txt --single-version-externally-managed failed with error code 1 in c:\users\user\appdata\local\temp\pip_build_USER\matplotlib

Exception information:
Traceback (most recent call last):
  File "C:\python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\basecommand.py", line 134, in main
    status = self.run(options, args)
  File "C:\python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\commands\install.py", line 241, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "C:\python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 1298, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "C:\python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 625, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "C:\python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\util.py", line 670, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command C:\python27\python.exe -c "import setuptools;__file__='c:\\users\\user\\appdata\\local\\temp\\pip_build_USER\\matplotlib\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\user\appdata\local\temp\pip-yplfpm-record\install-record.txt --single-version-externally-managed failed with error code 1 in c:\users\user\appdata\local\temp\pip_build_USER\matplotlib

为了尝试解决此错误,我们尝试使用以下下载进行安装:https://pypi.python.org/pypi/matplotlib/1.3.0

安装程序返回以下详细信息,然后从屏幕上消失。

BUILDING MATPLOTLIB
            matplotlib: yes [1.3.0]
                python: yes [2.7.5 (default, May 15 2013, 22:43:36) [MSC
                        v.1500 32 bit (Intel)]]
              platform: yes [win32]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.7.1]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: yes [Unknown version]
                   png: yes [pkg-config information for 'libpng' could not
                        be found. Using unknown version.]

OPTIONAL SUBPACKAGES
           sample_data: yes [installing]
              toolkits: yes [installing]
                 tests: yes [nose 0.11.1 or later is required to run the
                        matplotlib test suite]

OPTIONAL BACKEND EXTENSIONS
                macosx: no  [Mac OS-X only]
                qt4agg: no  [PyQt4 not found]
               gtk3agg: no  [Requires pygobject to be installed.]
             gtk3cairo: no  [Requires cairo to be installed.]
                gtkagg: no  [Requires pygtk]
                 tkagg: no  [The C/C++ header for Tk (tk.h) could not be
                        found.  You may need to install the development
                        package.]
                 wxagg: no  [requires wxPython]
                   gtk: no  [Requires pygtk]
                   agg: yes [installing]
                 cairo: no  [cairo not found]
             windowing: yes [installing]

OPTIONAL LATEX DEPENDENCIES
                dvipng: yes [version file.]
           ghostscript: yes [version 'gswin32c' is not recognized as an
                        internal or external command,  operable program or
                        batch file. ]
                 latex: no
               pdftops: no

我们假设它已经正确安装,因为我们没有看到错误,所以我们尝试了以下示例代码:

import matplotlib.pyplot as plt
#import numpy as np
plt.plot([1,2,3,4],[4,7,9,12])
plt.show()

不幸的是,它返回了以下回溯:

Traceback (most recent call last):
File "C:\matplotlib_test.py", line 1, in <module>
    import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot

有谁知道如何让它正常工作?

最佳答案

matplotlib 需要 dateutil、pyparsing 和 numpy 包才能运行。执行 pip install python-dateutilpip install pyparsing 如果您没有 numpy,也可以安装它。安装所有这些依赖项后,matplotlib 应该可以工作了。

如果您查看安装程序的消息,您可以看到依赖项列表:

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.7.1]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: yes [Unknown version]
                   png: yes [pkg-config information for 'libpng' could not
                        be found. Using unknown version.]

关于python - 无法让 matplotlib 使用简单绘图的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19127149/

相关文章:

python - 为什么 fill_between 在这里不起作用?

python - 当键乱序时比较字典列表

python - Beautiful Soup 无法从表中获取信息

python-2.7 - 如何在 Tensorflow 中增加变量?

python - 如何将小数点后 1 位舍入为小数点后 2 位

python - Pandas 子图布局在这种情况下不起作用

python - 如何查找 <tag>...</> 指定的内容的字符位置? Python

python - 如何在其他设备/磁盘上安装和运行 rodeo-python?

python 映射/减少 : emit multiple keys values from single map lambda

python - matplotlib 阴影线和填充直方图