2017-07-12 17 views
0

我是python的新手,我在github上發現這個項目「https://github.com/jadsonbr/pyreport」,我想打印來自mysql服務器的發票。我安裝pyreport和jasperpy但是當我嘗試運行代碼我得到這個錯誤:pyreport和jasperpy,我運行代碼時出錯

Traceback (most recent call last): 
    File "E:/onedrive/Documents/optimpos/module/fact_print.py", line 36, in <module> 
    compiling() 
    File "E:/onedrive/Documents/optimpos/module/fact_print.py", line 9, in compiling 
    jasper = pyjasper.JasperPy() 
AttributeError: 'module' object has no attribute 'JasperPy' 

我fact_print.py看起來是這樣的:

import os,sys,subprocess 
from platform import python_version 
import pyjasper 
sys.stderr = open("errlog.txt", "w") 

def compiling(): 
    input_file = os.path.dirname(os.path.abspath(__file__)) + \ 
       '/Invoice_2.jrxml' 
    jasper = pyjasper.JasperPy() 
    jasper.compile(input_file) 

def advanced_example_using_database(): 
    input_file = os.path.dirname(os.path.abspath(__file__)) + \ 
       '/Invoice_2.jrxml' 
    output = os.path.dirname(os.path.abspath(__file__)) + '/' 
    con = { 
     'driver': 'mysql', 
     'username': 'admin1', 
     'password': 'marcopolo', 
     'host': 'localhost', 
     'database': 'optimpos', 
     'schema': 'temp_vanzari', 
     'port': '3306' 
    } 
    jasper = pyjasper.JasperPy() 
    jasper.process(
     input_file, 
     output_file=output, 
     format_list=["pdf", "rtf", "xml"], 
     parameters={'python_version': python_version()}, 
     db_connection=con, 
     locale='en_US' # LOCALE Ex.:(en_US, de_GE) 
    ) 
    print("done printing") 

這可能是一個簡單的答案,但我不是能找到爲什麼pyjasper.JasperPy()不起作用。我正在使用pyhton 2.7

這只是一個測試代碼,mysql服務器僅供測試。 需要一些幫助,謝謝

+1

[AttributeError:'module'object has no attribute](https://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute)&[Python AttributeError:'module'對象沒有屬性'Serial'](https://stackoverflow.com/q/11403932/876298) –

回答

0

我遇到了同樣的問題。 Git頁面上的教程很混亂,我的印象是我可以直接從克隆的repo pyjasper/中導入。我有的解決方案是:

from pyjasper.jasperpy import JasperPy

一旦我這樣做,我能夠繼續教程。