openpreserve / jpylyzer

JP2 (JPEG 2000 Part 1) validator and properties extractor. Jpylyzer was specifically created to check that a JP2 file really conforms to the format's specifications. Additionally jpylyzer is able to extract technical characteristics.
http://jpylyzer.openpreservation.org/
Other
69 stars 28 forks source link

2.1.0 Launching jpylyzer result in Attempted relative import in non-package #194

Closed TechiesOfficial closed 10 months ago

TechiesOfficial commented 10 months ago

Hello, working for BnF, we try to update to the last jyplyzer version (2.1) using python 2.7 before migrating to 3.2.

I've seen package import definition have changed between 2.0 and 2.1 and launching jpylyzer results in:

python jpylyzer.py Traceback (most recent call last): File "jpylyzer.py", line 45, in <module> from . import config ValueError: Attempted relative import in non-package

I am not really familiar with python package definition but everything seems correct. There is a init.py file as can be seen: boxvalidator.py byteconv.py config.py etpatch.py __init__.py jpylyzer.py jpylyzer$py.class __main__.py mix.py shared.py

I tried with a python3.6 executable that was already available on the server but same result.

Thanks.

bitsgalore commented 10 months ago

Hi,

This happens because of the slightly different ways imports work in Python, depending on whether you run a Python application from an installed package, or from a script in the source distribution.

The easiest solution (and the only proper one for production use!), is to install Jpylyzer either as a Python package (using pip), or alternatively using the Windows binaries or the Debian package. See the docs for details:

https://jpylyzer.openpreservation.org/doc/latest/userManual.html#installation

In that case you can directly run jpylyzer as an executable command, without having to worry about the Python interpreter.

If you really want to run Jpylyzer from the source distribution (which seems to be what you're doing), you can use the cli.py wrapper script, which is located in the root of the repo. E.g. on Linux:

python3 ~/jpylyzer/cli.py 

Result:

usage: cli.py [-h] [--format FMT] [--legacyout] [--mix {1,2}] [--nopretty]
              [--nullxml] [--recurse] [--packetmarkers] [--verbose]
              [--version] [--wrapper]
              jp2In [jp2In ...]
cli.py: error: the following arguments are required: jp2In

Let me know if this helps!

bitsgalore commented 10 months ago

Side note - you mention upgrading to Python 3.2. Not sure if that's a typo, but I would strongly recommend to upgrade to a more recent (3.8 or higher) version, because Python 3.2 was retired in early 2016, see overview here:

https://devguide.python.org/versions/

TechiesOfficial commented 10 months ago

We use jython nowaday and my manager came back from vacation and created a specific package.

We will throw away jython in our next updates.

There is nothing wrong on your side.

Thank you for your time.