libracore / erpnextswiss

ERPNext application for Switzerland-specific use cases
GNU Affero General Public License v3.0
74 stars 63 forks source link

ImportError: Module import failed for ZUGFeRD Wizard #120

Closed n0va8 closed 8 months ago

n0va8 commented 1 year ago

Expected behaviour

ERPNextSwiss is correctly installed on frappe/ERPNext branch v13.

Actual behaviour

Installation is aborted while updating DocTypes for erpnext at 48%. Error message:

Installing erpnextswiss...
Updating DocTypes for erpnextswiss  : [===================                     ] 48%An error occurred while installing erpnextswiss: Module import failed for ZUGFeRD Wizard (erpnextswiss.erpnextswiss.doctype.zugferd_wizard.zugferd_wizard Error: libGL.so.1: cannot open shared object file: No such file or directory)
Traceback (most recent call last):
  File "apps/frappe/frappe/modules/utils.py", line 243, in load_doctype_module
    doctype_python_modules[key] = frappe.get_module(module_name)
  File "apps/frappe/frappe/__init__.py", line 1206, in get_module
    return importlib.import_module(modulename)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "apps/erpnextswiss/erpnextswiss/erpnextswiss/doctype/zugferd_wizard/zugferd_wizard.py", line 10, in <module>
    from erpnextswiss.erpnextswiss.zugferd.qr_reader import find_qr_content_from_pdf, get_content_from_qr
  File "apps/erpnextswiss/erpnextswiss/erpnextswiss/zugferd/qr_reader.py", line 10, in <module>
    import cv2              # part of opencv-python
  File "env/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "env/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 293, in install_app
    _install_app(app, verbose=context.verbose)
  File "apps/frappe/frappe/installer.py", line 186, in install_app
    sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
  File "apps/frappe/frappe/model/sync.py", line 73, in sync_for
    import_file_by_path(
  File "apps/frappe/frappe/modules/import_file.py", line 146, in import_file_by_path
    import_doc(
  File "apps/frappe/frappe/modules/import_file.py", line 275, in import_doc
    doc.insert()
  File "apps/frappe/frappe/model/document.py", line 293, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1087, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 943, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 940, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 376, in on_update
    self.run_module_method("on_doctype_update")
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 435, in run_module_method
    module = load_doctype_module(self.name, self.module)
  File "apps/frappe/frappe/modules/utils.py", line 245, in load_doctype_module
    raise ImportError(
ImportError: Module import failed for ZUGFeRD Wizard (erpnextswiss.erpnextswiss.doctype.zugferd_wizard.zugferd_wizard Error: libGL.so.1: cannot open shared object file: No such file or directory)

Observed in (version)

Steps to reproduce

  1. Install frappe_docker to deploy frappe/erpnext on single server: https://github.com/frappe/frappe_docker/blob/main/docs/single-server-example.md

  2. Get app from git with bench: sudo docker compose --project-name PROJECTNAME exec backend bench get-app https://github.com/libracore/erpnextswiss.git OUTPUT- WARNING - "WARN: restart failed: Couldn't find supervisorctl in PATH"

  3. Install app with bench sudo docker compose --project-name PROJECTNAME exec backend bench --site SITENAME install-app erpnextswiss

lasalesi commented 1 year ago

Thanks for your feedback. You have an issue with a dependency: libGL.so.1 is not properly installed.

The latest versions of ERPNextSwiss introduce the purchase invoice automation module, which uses PDF analytics to read purchase invoice pdfs and import them automatically into ERPNext. In order to achieve this, we are usinf PyMuPDF and OpenCV. Depending on your Python version, you might need to install other versions than the default here.

There is also more information on https://github.com/libracore/erpnextswiss/wiki/Troubleshooting

Without knowing you OS/Pyhton version, this is difficult to answer, but you could try running

$ sudo env/bin/pip install pymupdf==1.16.18
$ sudo env/bin/pip install opencv-python==3.4.13.47
bosue commented 1 year ago

Same here. Unfortunately didn‘t get it to properly install on Frappe Cloud. Will figure it out on my own machine, though.

Might a pyproject.toml help ensuring there’s a proper requirements check right in the beginning, to avoid errors and other avoidable problems with a semi-installed module?

checkin247 commented 1 year ago

I seem to run in the same issues here: Environment: ERPNext v14.37.1 -> Dockercontainer

additional steps taken: 1) removed erpnextswiss and installed with --resolve-deps (bench get-app --resolve-deps erpnextswiss https://github.com/libracore/erpnextswiss.git) and bench install-app erpnextswiss

then I get:

Installing erpnextswiss...
Updating DocTypes for erpnextswiss  : [=======                                 ] 17%An error occurred while installing erpnextswiss: Module import failed for ZUGFeRD Wizard, the DocType you're trying to open might be deleted.<br> Error: libGL.so.1: cannot open shared object file: No such file or directory
Traceback (most recent call last):
  File "apps/frappe/frappe/modules/utils.py", line 245, in load_doctype_module
    doctype_python_modules[key] = frappe.get_module(module_name)
  File "apps/frappe/frappe/__init__.py", line 1342, in get_module
    return importlib.import_module(modulename)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "apps/erpnextswiss/erpnextswiss/erpnextswiss/doctype/zugferd_wizard/zugferd_wizard.py", line 10, in <module>
    from erpnextswiss.erpnextswiss.zugferd.qr_reader import find_qr_content_from_pdf, get_content_from_qr
  File "apps/erpnextswiss/erpnextswiss/erpnextswiss/zugferd/qr_reader.py", line 10, in <module>
    import cv2              # part of opencv-python
  File "env/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "env/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 415, in install_app
    _install_app(app, verbose=context.verbose, force=force)
  File "apps/frappe/frappe/installer.py", line 297, in install_app
    sync_for(name, force=force, reset_permissions=True)
  File "apps/frappe/frappe/model/sync.py", line 109, in sync_for
    import_file_by_path(
  File "apps/frappe/frappe/modules/import_file.py", line 145, in import_file_by_path
    import_doc(
  File "apps/frappe/frappe/modules/import_file.py", line 242, in import_doc
    doc.insert()
  File "apps/frappe/frappe/model/document.py", line 287, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1090, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 917, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1279, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1261, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 914, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 407, in on_update
    self.run_module_method("on_doctype_update")
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 492, in run_module_method
    module = load_doctype_module(self.name, self.module)
  File "apps/frappe/frappe/modules/utils.py", line 249, in load_doctype_module
    raise ImportError(msg) from e
ImportError: Module import failed for ZUGFeRD Wizard, the DocType you're trying to open might be deleted.<br> Error: libGL.so.1: cannot open shared object file: No such file or directory
bvisible commented 1 year ago

We had the same error on an ubuntu server and we passed this error with sudo apt-get install libgl1-mesa-glx -y

lasalesi commented 11 months ago

This might be caused the the new dependencies we have for image processing (in order to automatically process purchase invoices).

Please refer to the wiki page at

https://github.com/libracore/erpnextswiss/wiki/Troubleshooting

latoile commented 11 months ago

I was able to resolve the error by installing the pymupdf package.

sudo env/bin/pip install pymupdf
n0va8 commented 7 months ago

Sorry to reopen the issue and thank you for the inputs so far.

I have installed the libGL.so.1 dependencies as recommended in the troubleshooting: $ sudo apt update && sudo apt install ffmpeg libsm6 libxext6

And @bvisible's hint: sudo apt-get install libgl1-mesa-glx

Now I am getting the following error message after adding the ZUGFeRD DocType and reinstalling erpnextswiss:

[...]/apps/erpnextswiss/erpnextswiss/erpnextswiss/doctype/zugferd_wizard/zugferd_wizard.py", line 9, in <module>
    from erpnextswiss.erpnextswiss.zugferd.zugferd import get_xml, get_content_from_zugferd
ImportError: cannot import name 'get_xml' from 'erpnextswiss.erpnextswiss.zugferd.zugferd' (/home/frappe/frappe-bench/apps/erpnextswiss/erpnextswiss/erpnextswiss/zugferd/zugferd.py)
...
apps/frappe/frappe/modules/utils.py", line 245, in load_doctype_module
    raise ImportError(
ImportError: Module import failed for ZUGFeRD Wizard (erpnextswiss.erpnextswiss.doctype.zugferd_wizard.zugferd_wizard Error: cannot import name 'get_xml' from 'erpnextswiss.erpnextswiss.zugferd.zugferd'[...]

Additional version information: debian 11 python 3.9.17 opencv-python 4.8.0.74 pymupdf 1.22.5