[Ev...] Posted April 11 Share Posted April 11 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 More sharing options...
[Ma...] Posted April 12 Share Posted April 12 Hi, does it work to import a package using an absolute path? E.g.: # -*- coding: utf-8 -*- # submodule.py import gom from Toplevel import topmodule Regards, Matthias Link to comment Share on other sites More sharing options...
[Ev...] Posted April 12 Author Share Posted April 12 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 More sharing options...
[Ma...] Posted April 17 Share Posted April 17 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 More sharing options...
[Ev...] Posted April 17 Author Share Posted April 17 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 More sharing options...
[Ma...] Posted May 3 Share Posted May 3 (edited) I have got it running, well at least it runs until the "Start Menu"-dialog with the "Prepare Measurement"-button, so it looks like all imports are working here. Sorry, I cannot test this further, no equipment ready... What have I done: 1) Move start scripts out of the "Kiosk" package: and adapted the imports to use relative imports into the "Kiosk" package. There are two places, the one shown in the picture and in lines 113ff: def tryToImportStandardTest(name=""): try: exec('from Kiosk.StandardTests import %s' % name) 2) Adapt the imports in the "Kiosk" package to use relative import from ".", for example in Basetest.py: # import from standard system scripts: from . import Functions from . import Dialogs from . import Variables There are about 10 imports in the toplevel scripts in "Kiosk". I hope this helps and that it's also working for the complete workflow. Edited May 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in