invinet / python-en16931

A Python 3 package to parse, generate and manage the EN16931 Invoice format.
https://invinet.github.io/python-en16931/
Apache License 2.0
24 stars 8 forks source link

The 'en16931' package was not installed in a way that PackageLoader understands #7

Closed maikelmertens closed 9 months ago

maikelmertens commented 9 months ago

I've stumbled upon an issue with using this library, when I try to import this library, more specifically with from en16931 import Invoice, it will yield an error:

Traceback (most recent call last):
  File "/home/x/app.py", line 1, in <module>
    from en16931 import Invoice
  File "/home/x/.venv/lib/python3.10/site-packages/en16931/__init__.py", line 12, in <module>
    from en16931.invoice import Invoice
  File "/home/x/.venv/lib/python3.10/site-packages/en16931/invoice.py", line 21, in <module>
    templates = Environment(loader=PackageLoader('en16931', 'templates'))
  File "/home/x/.venv/lib/python3.10/site-packages/jinja2/loaders.py", line 323, in __init__
    raise ValueError(
ValueError: The 'en16931' package was not installed in a way that PackageLoader understands.

Searching on internet, the problem seem to be related to jinja and packaging data. Any help in order to resolve this, is appreciated.

jtorrents commented 9 months ago

Thanks for the report @maikelmertens ! The issue should be fixed now. I released a new version of the package to pypi with the fix and some of the features contributed by @mcmihai

Could you please try installing/upgrading from:

https://pypi.org/project/en16931/0.1.2/

Thanks!

maikelmertens commented 9 months ago

Thanks for your prompt response @jtorrents. Much appreciated.

I've upgraded the en16931 package, but the issue, unfortunately, remains. Please see the following output:

❯ pip show en16931
Name: en16931
Version: 0.1.2
Summary: A Python 3 package to parse, generate and manage the EN16931 Invoice format
Home-page: https://github.com/invinet/python-en16931
Author: Invinet Sistemes
Author-email: jtorrents@ingent.net

This will output the same error, apart from a line number that has changed:

Traceback (most recent call last):
  File "/home/x/app.py", line 1, in <module>
    from en16931 import Invoice
  File "/home/x/.venv/lib/python3.10/site-packages/en16931/__init__.py", line 12, in <module>
    from en16931.invoice import Invoice
  File "/home/x/.venv/lib/python3.10/site-packages/en16931/invoice.py", line 22, in <module>
    loader=PackageLoader("en16931"),
  File "/home/x/.venv/lib/python3.10/site-packages/jinja2/loaders.py", line 323, in __init__
    raise ValueError(
ValueError: The 'en16931' package was not installed in a way that PackageLoader understands.
mcmihai commented 9 months ago

it can't find the template. if you were to copy the templates directory from this repo to "/home/x/.venv/lib/python3.10/site-packages/en16931/" it would work.

jtorrents commented 9 months ago

I'll take a deeper look at Jinja docs tomorrow. I'm sure I'm missing something obvious. I thought the problem was resolved because installing with pip for development:

$ pip install -e ~/projects/python-en16931

Does not raise the error.

maikelmertens commented 9 months ago

The solution @mcmihai provided indeed solved the issue. I've created a small PR to add the templates directory and to automatically install the dependencies while installing this package: https://github.com/invinet/python-en16931/pull/8

jtorrents commented 9 months ago

Thanks @maikelmertens! I merged your pull request and deployed a new version 0.1.3 to pypi:

https://pypi.org/project/en16931/0.1.3/

Now we are able to find the templates after installation as @mcmihai indicated.

maikelmertens commented 9 months ago

The version 0.1.3 works like a charm now, no issues in using this package. Thank you too @jtorrents and @mcmihai!