[1.1.0] Jython 2.7.0: using openpyxl (import errors) (Jython problem)

Asked by Daniel Kurtz

Attempting to use the excellent openpyxl module for working with Excel files (much more convenient than using the triumvirate of XLRD, XLWT and XLUtils). Have tried this both by putting a copy of the openpyxl directory in the LIB folder and by adding the Python SITE_PACKAGES folder to the sys.path.

In 1.01, the 'import openpyxl' statement returns:

     [error] SyntaxError ( ("'import *' not allowed with 'from .'", ('C:\\Sikuli\\Lib\\openpyxl\\workbook\\__init__.py', 5, 0, '')) )

I understand is a Jython issue, since Jython 2.5 specifically does not allow this type of import.

So I tried 1.1, to see if stepping up to Jython 2.7 makes a difference. Apparently it does, because the import statement now returns

     [error] ImportError ( No module named workbook )

So Jython 2.7 apparently does allow the 'import *' construct, and I suspect that now we're looking at a pathing issue of some sort.

I find that by adding 'lib\openpyxl' and 'lib\openpyxl\workbook' to the sys.path, that I can generate different errors, such as"

    [error] ImportError ( Workbook.sikuli has no Workbook.py )

Now this is interesting... how did the folder 'workbook' become 'workbook.sikuli'? And in any event, there is no 'Workbook.py' because the file is named 'workbook.py', though the CLASS within is named 'Workbook'.

I'm not that proficient yet with Python (much prefer Ruby for scripting) and no next to nothing about the nasty intricacies of the Java/Jython environment so any suggestions are appreciated. I guess in the meantime I'll have to go with the XL* trio of modules... or maybe just convert our spreadsheets to CSV and go that route.

ddk

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Daniel Kurtz
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

I will have a look at openpyxl and give you a solution as soon as possible.

The " Workbook.sikuli"-problem should be fixed with the latest build of 1.1.0, if not, please give me a note.

With 1.1.0 the xl-triumvirate is bundled. so you simply have to import ;-)

Revision history for this message
Daniel Kurtz (dkurtz-p) said :
#2

Thanks Raimund. I'll get the latest nightly and let you know how the 'workbook.sikuli' issue at least works out. I've been playing with the import in the Jython interpreter and got some more detailed error info:

     >>> import openpyxl
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "C:\jython2.7.0\Lib\site-packages\openpyxl\__init__.py", line 9, in <module>
         from openpyxl.workbook import Workbook
       File "C:\jython2.7.0\Lib\site-packages\openpyxl\workbook\__init__.py", line 5, in <module>
         from .workbook import *
     ImportError: No module named workbook

I had heard that Jython 2.5 flatly did not support the 'from <module> import *' syntax but had SORTA heard that Jython 2.7 does (can't find a definitive declaration anywhere that it does) but it looks like we're still dying on that same statement. Just with a different error message. I'm already conversing with openpyxlGuy, but I think it's moving into JythonGuy's court.

ddk

Revision history for this message
RaiMan (raimund-hocke) said :
#3

I tested with the latest nightly 1.1.0 and got the same errors.

the cause seems to be the

from .workbook import *

in
workbook/__init__.py

the easiest solution would be, that the openpyxlGuy resolves the .workbook shortcut to a series of normal imports.

Revision history for this message
Daniel Kurtz (dkurtz-p) said :
#4

Thanks, Raimund. I concur. Unfortunately there's a lot of that throughout the package. I understand it's officially considered bad practice but the openpyxl people think they have a compelling reason for doing it that way (rather than just being lazy.) I might give it a try though for the time being I think I'll just work out how to make do with XL*. Or I guess I have the option of going with a Java library, like Poi, don't I?

ddk

Revision history for this message
RaiMan (raimund-hocke) said :
#5

I just tested:

with 1.1.0 the bundled xlrd 0.9.3 works fine.