django1.1.4中的ImportError,但我可以单独执行此文件

时间:2019-01-15 03:09:39

标签: python django

我正在运行python2.5,python 1.1.4程序,当我尝试导入文件时,我得到了一个名为pie Exception的No模块,但是我可以单独运行此文件,因为该程序太旧了,我不知道该怎么办。

为了避免路径问题,我将需要导入的代码放入视图中。但是这部分代码取决于cairopycha.pie,如果我不执行django程序,而自己执行该文件,那很好,所以我可以确定django的原因。 / p>

import cairo
import pycha.pie

def pieChart(lines,out_file,title=u"images"):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 300, 220)
    datas = [(line[0], [[0, line[1]]]) for line in lines]
    options = {
        'axis': {
            'labelFont': 'simsun' ,
            'tickFont':'simsun',  
            'tickFontSize':12.0,
            'line': {
                'ticks': [dict(v=i, label=d[0]) for i, d in enumerate(lines)],
            },
        },
        'colorScheme': { 'name':'fixed' ,
            'args': {
                'colors': [line[2] for line in lines],
                },
        },
        'title':title,
        'labelFont': 'simsun' ,
        'titleFont': 'simsun' ,
        'background': { 'hide': True, },
        'pieRadius':0.3,
        'padding': {
            'left': 3,
            'right': 3,
            'top': 3,
            'bottom': 3,
        },
        'legend': { 'hide': True, },
    }
    chart = pycha.pie.PieChart(surface, options)
    chart.addDataset(datas)
    chart.render()
    surface.write_to_png(out_file)

if __name__ == "__main__":
    lines=[ ['a',1,'#ff0000'],[u'hello',2,'#00ff00']]
    pieChart(lines,'demo.png')
    print "file done!"

Django错误

ImportError at /
No module named pie
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Exception Type: ImportError
Exception Value:    
No module named pie

如果使用django启动程序,则会出现此错误,我自己正确执行了上述代码。

0 个答案:

没有答案