Python 无法打印图形:打印时需要matplotlib
我能够生成*.dat文件:Python 无法打印图形:打印时需要matplotlib,python,matplotlib,graph,memory-profiling,guppy,Python,Matplotlib,Graph,Memory Profiling,Guppy,我能够生成*.dat文件: vikas@server:~/memory_profiler-0.36$ ./mprof run --python test_sl.py vikas@server:~/memory_profiler-0.36$ ls *.dat mprofile_20151001035123.dat 但当我试图绘制图形时,它会说“绘制需要matplotlib” 我错过什么了吗 我正在评测的函数是run(),它位于:file_to_be_profiled.py中 #!/usr/bi
vikas@server:~/memory_profiler-0.36$ ./mprof run --python test_sl.py
vikas@server:~/memory_profiler-0.36$ ls *.dat
mprofile_20151001035123.dat
但当我试图绘制图形时,它会说“绘制需要matplotlib”
我错过什么了吗
我正在评测的函数是run(),它位于:file_to_be_profiled.py中
#!/usr/bin/python
import time
import os, sys, commands
from memory_profiler import profile
from guppy import hpy
@profile
def run():
d = {}
l = []
hp = hpy()
before = hp.heap()
d["k1"] = 'val1'
d["k2"] = 10
count = 0
while (count < 9):
l.append(count)
print 'The count is:', count
count = count + 1
print "Good bye!"
after = hp.heap()
leftover = after - before
print leftover
if __name__ == '__main__':
sys.exit(run())
我在ubuntu机器上运行。但apt get安装对我不起作用。然后我从源代码处进行了安装。但我也会犯同样的错误 apt get失败:
vikas@server:~/memory_profiler-0.36$ sudo apt-get install -y python-matplotlib
[sudo] password for vikaskuk:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python-matplotlib is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python-matplotlib' has no installation candidate
vikask@server:~/memory_profiler-0.36$ ./mprof plot --output=plot.png
matplotlib is needed for plotting.
然后我尝试了pip安装。。。也没有通过:
vikas@server:~/memory_profiler-0.36$ pip install matplotlib
Downloading/unpacking matplotlib
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement matplotlib
Cleaning up...
No distributions at all found for matplotlib
Storing debug log for failure in /home/vikaskuk/.pip/pip.log
最后,我尝试从源代码安装,似乎成功了:
vikas@server:~/memory_profiler-0.36$ cd ../matplotlib
vikas@server:~/matplotlib$ cd matplotlib-master/
(virtualenv)vikaskuk@beehive:~/matplotlib/matplotlib-master$ vi INSTALL
(virtualenv)vikaskuk@beehive:~/matplotlib/matplotlib-master$ python setup.py build
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.5.dev1]
python: yes [2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC
4.4.5]]
platform: yes [linux2]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [not found. pip may install it below.]
six: yes [using six version 1.5.2]
dateutil: yes [using dateutil version 2.1]
pytz: yes [pytz was not found. pip will 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.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: no [pkg-config information for 'libpng' could not
be found.]
qhull: yes [pkg-config information for 'qhull' could not be
found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: yes [using nose version 1.3.0 / using mock 1.0.1]
toolkits_tests: yes [using nose version 1.3.0 / using mock 1.0.1]
OPTIONAL BACKEND EXTENSIONS
macosx: no [Mac OS-X only]
qt5agg: no [PyQt5 not found]
qt4agg: no [PySide not found; PyQt4 not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo 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 [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
OPTIONAL LATEX DEPENDENCIES
dvipng: no
ghostscript: yes [version 8.71]
latex: yes [version 3.1415926]
pdftops: no
============================================================================
* The following required packages can not be built:
* freetype, png
(virtualenv)vikaskuk@beehive:~/matplotlib/matplotlib-master$ python setup.py install
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.5.dev1]
python: yes [2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC
4.4.5]]
platform: yes [linux2]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [not found. pip may install it below.]
six: yes [using six version 1.5.2]
dateutil: yes [using dateutil version 2.1]
pytz: yes [pytz was not found. pip will 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.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: no [pkg-config information for 'libpng' could not
be found.]
qhull: yes [pkg-config information for 'qhull' could not be
found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: yes [using nose version 1.3.0 / using mock 1.0.1]
toolkits_tests: yes [using nose version 1.3.0 / using mock 1.0.1]
OPTIONAL BACKEND EXTENSIONS
macosx: no [Mac OS-X only]
qt5agg: no [PyQt5 not found]
qt4agg: no [PySide not found; PyQt4 not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo 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 [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
OPTIONAL LATEX DEPENDENCIES
dvipng: no
ghostscript: yes [version 8.71]
latex: yes [version 3.1415926]
pdftops: no
============================================================================
* The following required packages can not be built:
* freetype, png
但当我试图绘制图表时,我碰到了最初的问题:
vikas@server:~/matplotlib/matplotlib-master$ cd ../../memory_profiler-0.36
vikas@server:~/memory_profiler-0.36$ ./mprof plot --output=plot.png
matplotlib is needed for plotting.
我成功地完成了apt-get-update(出现了一些防火墙问题,然后我成功地完成了:sudo-apt-get-install-y python-matplotlib)
但我在运行mprof时仍然遇到一些问题:
vikas@server:~/memory_profiler-0.36$ ./mprof plot --output=plot.png
Using last profile data.
Traceback (most recent call last):
File "./mprof", line 494, in <module>
actions[get_action()]()
File "./mprof", line 454, in plot_action
pl.figure(figsize=(14, 6), dpi=90)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
vikas@server:~/memory\u profiler-0.36$./mprof plot--output=plot.png
使用最后的配置文件数据。
回溯(最近一次呼叫最后一次):
文件“/mprof”,第494行,在
操作[get_action()]()
文件“/mprof”,第454行,在绘图动作中
pl.图(figsize=(14,6),dpi=90)
文件“/usr/lib/pymodules/python2.7/matplotlib/pyplot.py”,图中第423行
**kwargs)
文件“/usr/lib/pymodules/python2.7/matplotlib/backends/backend\u tkagg.py”,第79行,在新的图形管理器中
返回新的\u图形\u管理器\u给定的\u图形(num,figure)
文件“/usr/lib/pymodules/python2.7/matplotlib/backends/backend\u tkagg.py”,第87行,在新的\u图\u管理器\u给定的\u图中
window=Tk.Tk()
文件“/usr/lib/python2.7/lib tk/Tkinter.py”,第1767行,在__
self.tk=\u tkinter.create(屏幕名、基本名、类名、交互、wantobjects、useTk、同步、使用)
_tkinter.TclError:没有显示名称和$display环境变量
为什么我需要设置显示器?我正在ubuntu主机上工作。您需要按照说明安装
matplotlib
您可以使用pippip安装matplotlib
(您可能需要在其前面加上sudo
)或您的软件包管理器来执行此操作:
在Debian、Ubuntu及其衍生物上sudo apt get安装-y python matplotlib
在RHEL、CentOS及其衍生产品上sudo-yum安装-y python-matplotlib
- 我也有同样的问题。我使用memory_profiler lib键入以下命令
(
mprof运行runner.py
和mprof plot
)并收到一条消息“打印需要matplotlib”
我试图按照我在这里找到的建议解决这个问题,但结果我通过完成以下简单步骤解决了这个问题:
sudo-yum-builddep-python-matplotlib
安装连接的软件包(已安装222个软件包,如果需要apt-get,则需要此命令:sudo-apt-get-build-dep-python-matplotlib
)sudo yum重新安装python matplotlib
(或者使用install命令,使用apt get:sudo apt get安装python matplotlib
)我相信这会有所帮助。我在新安装的Ubuntu 16.04上也遇到了同样的问题。为了解决这个问题,我安装了如下SciPy:
sudopip安装scipy
我还必须像这样安装tkinter
lib:
sudo-apt-get-install-python-tk
我想在过去的某个地方,matplotlib有
scipy
作为依赖项,但现在它只有numpy,而mprof plot
需要scipy在conda环境中,matplotlib:3.0.1似乎与python 3.7不兼容。
无法正确执行df.plot()命令,显示“ImportError:打印需要matplotlib”,但实际上已安装matplotlib
我尝试将matplotlib降级到3.0.0,然后一切都很好
康达安装-n[你的康达环境]matplotlib==3.0.0我正在ubuntu机器上运行。但apt get安装对我不起作用。然后我从源代码处进行了安装。用我所做的步骤编辑问题。@vikas确保您解释了为什么apt get install
不适合您。是否有错误消息?我的组织中可能存在某种防火墙。。。这就是apt get失败的原因。因此,我尝试了源代码安装,看起来成功了。但是,原来的问题仍然存在。请看我原来的问题。。。。我现在已经用我所做的一切进行了编辑。@vikas否,源代码安装失败(请参见输出的结尾)。在运行apt get install
之前,请尝试运行sudo apt get update
。你需要让apt-get
在某个时刻起作用,因为你缺少了matplotlib
的许多依赖项,apt-get
实际上是获得它们的唯一方法。成功后apt-get-update我能够安装matplotlib。。。但mprof仍然抱怨显示器。请看一下原来的问题。我引用了我得到的错误。实际上,您从源代码构建的版本也没有成功。您的计算机上没有安装freetype
或libpng
,因此matplotlib无法生成pip安装
遇到了一个单独的问题(你是在防火墙后面吗?),但很快就会遇到同样的问题。我不知道为什么通过软件包管理器进行安装时会遇到问题,但请先安装libfreetype6 dev
、libpng dev
、以及python tk
,然后您应该能够从源代码进行构建。
vikas@server:~/matplotlib/matplotlib-master$ cd ../../memory_profiler-0.36
vikas@server:~/memory_profiler-0.36$ ./mprof plot --output=plot.png
matplotlib is needed for plotting.
vikas@server:~/memory_profiler-0.36$ ./mprof plot --output=plot.png
Using last profile data.
Traceback (most recent call last):
File "./mprof", line 494, in <module>
actions[get_action()]()
File "./mprof", line 454, in plot_action
pl.figure(figsize=(14, 6), dpi=90)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable