pyreport and jasperpy, i have an error with running the code

825 views Asked by At

I'm new to python, and i have found on github this project "https://github.com/jadsonbr/pyreport", i want to print invoices from a mysql server. I installed pyreport and jasperpy but when i try to run the code i get this error:

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'

My fact_print.py looks like this:

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")

It might be an easy answer but i wasnt able to find why the pyjasper.JasperPy() won't work. I am using pyhton 2.7

This is just a test code, the mysql server is just for test. Need some help, and thanks

1

There are 1 answers

0
Ike On

I was having the same problem. The tutorial on the Git page is confusing and I was under the impression I could import directly from the cloned repo pyjasper/. The solution I had was to:

from pyjasper.jasperpy import JasperPy

Once I did that I was able to continue with the tutorial.