我不太了解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__
matplotlib.cbook的导入工作正常,但其他导致错误。
cbook.__file__ = '/opt/anaconda2/lib/python2.7/site-packages/matplotlib/cbook.py'
Traceback (most recent call last):
File "/site/web2py.2.13.4/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/site/web2py.2.13.4/applications/plotlab/controllers/version.py", line 53, in <module>
File "/site/web2py.2.13.4/gluon/globals.py", line 412, in <lambda>
self._caller = lambda f: f()
File "/site/web2py.2.13.4/applications/plotlab/controllers/version.py", line 41, in import_mathlab_figure
from matplotlib.figure import Figure
File "/site/web2py.2.13.4/gluon/custom_import.py", line 95, in custom_importer
return base_importer(pname, globals, locals, fromlist, level)
ImportError: No module named matplotlib.figure
Traceback (most recent call last):
File "/site/web2py.2.13.4/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/site/web2py.2.13.4/applications/plotlab/controllers/version.py", line 53, in <module>
File "/site/web2py.2.13.4/gluon/globals.py", line 412, in <lambda>
self._caller = lambda f: f()
File "/site/web2py.2.13.4/applications/plotlab/controllers/version.py", line 46, in import_mathlab_backends
from matplotlib.backends.backend_agg import FigureCanvasAgg
File "/site/web2py.2.13.4/gluon/custom_import.py", line 95, in custom_importer
return base_importer(pname, globals, locals, fromlist, level)
ImportError: No module named matplotlib.backends.backend_agg
所有这些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的类似问题,但是对于这个问题尚未接受答案。