web2py无法导入matplotlib模块

2024-09-28 22:03:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我不太理解web2py的custom_import.py的工作原理。我试图从mathplotlib导入模块,但得到的结果不一致。在

我的控制器version.py包含以下语句。在

def import_mathlab_cbook():
    import matplotlib.cbook as cbook
    return "cbook.__file__ = %r" % cbook.__file__

def import_mathlab_figure():
    from matplotlib.figure import Figure
    return "Figure.__file__ = %r" % Figure.__file__

def import_mathlab_backends():
    from matplotlib.backends.backend_agg import FigureCanvasAgg 
    return "FigureCanvasAgg.__file__ = %r" % FigureCanvasAgg.__file__

进口地图库.cbook工作正常,但其他人会出错。在

^{pr2}$

所有这些import语句都是从命令行工作的,当web2py在命令行运行时也是如此。在

# python web2py.py -S welcome -P
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2016
Version 2.13.4-stable+timestamp.2015.12.26.04.59.39
Database drivers available: sqlite3, imaplib, pymysql, pg8000
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 
>>> import matplotlib.cbook as cbook
>>> 
>>> from matplotlib.figure import Figure
>>> 
>>> from  matplotlib.backends.backend_agg import FigureCanvasAgg

我正在运行Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec 6 2015, 18:08:32)和web2py Version 2.13.4-stable+timestamp.2015.12.26.04.59.39。在

我知道有一个关于importing the copy_reg module的类似问题,但是这个问题的答案还没有被接受。在


Tags: frompyimportreturnmatplotlibdef语句backends