Jump to content

Relative module imports within Add-On Fails


---
 Share

Recommended Posts

---

Hi, we're trying to run tensile kiosk mode in 2023 Correlate.  The GOM-created script uses several relative imports.  For example in the StandardTensileKiosk_nonmetallic, it has 

from .. import Functions

This is failing with an error saying that the module is attempting to import beyond the top level package.  But it isn't.  The import is clearly referenced to a relative path within the top-level package.  When we made our own separate Add-On to experiment with relative import issues, we also observed an error saying that the module parent was not defined.

This issue has rendered tensile kiosk mode inoperable in 2023, and it is essential for our operations.  We are willing to make custom edits to the tensile kiosk mode and deploy it throughout our organization, but we're unclear on how to patch the code to make relative imports work within an Add-On.  Thanks for any help!

Link to comment
Share on other sites

---

Hi,

does it work to import a package using an absolute path?

E.g.:

image.png.bfdb3dbdfccd7a7a366d0fd56ccea81f.png

# -*- coding: utf-8 -*-
# submodule.py
import gom
from Toplevel import topmodule

Regards,

Matthias

Link to comment
Share on other sites

---

Please sign in to view this quote.

Thanks for the fast reply!  No, it didn't.  In the case of the tensile kiosk, the top-level is called "Kiosk", but when we try

from Kiosk import Functions

we similarly get an error saying Kiosk is not a known package.  (I apologize, I don't have access to machine at the moment to get a better image).  So if `local_dependency.py` is a file inside Kiosk along with a subfolder `sub` and a submodule `sub/subfile.py`, then the contents of Kiosk are on the path, but not the Kiosk package itself....so absolute import `Kiosk.local_dependency` does not work and neither does relative import `..local_dependency`.

Link to comment
Share on other sites

---

How do you start the Kiosk ? Where is the starting script located ?

(Sorry, it's been very long since I looked at aramis kiosk, and I don't have anything setup to try...)

 

Link to comment
Share on other sites

---

The startup script is called StartKiosk.py and is in a folder called "Kiosk" which is in the tensile kiosk Add On.  It then loads classes from a subfolder called StandardTests.  The files inside StandardTests try to load modules called Functions.py, Dialogs.py, etc. from the same folder as StartKiosk using relative import.
 

Link to comment
Share on other sites

 Share

×
×
  • Create New...