Python extension module

MarcAVallee
MarcAVallee Posts: 9 Calcite Rank Badge
edited February 2023 in GeoStudio
I have noticed that if I run an extension requesting a non geosoft module, the module must be in the python executable directory. If it is located in the user/python directory, it is not located by OM. Is there an alternative?

Comments

  • JacquesBeaurain
    JacquesBeaurain Posts: 29 Calcite Rank Badge
    edited November 2017
    Hi Marc,

    Only the extension script should live in the user/python directory. Just like the geosoft module any other modules that the script depends on should be installed using the standard package management system of the configured Python distribution (e.g. pip or conda). This usually means the module ends up in the Lib\site-packages directory of the active environment.

    Cheers,
    Jacques
  • @MarcVallée

    Jacques and I discussed this. Yes, this is a bit awkward because the extension is running inside the Geosoft environment. The simplest thing to do is to include all your modules inside you single script, which in Python practice is not such a bad thing.

    Alternately you can put a try-except around your import and in the exception add the path of your script to the process system path, then your import will be able to resolve. For example:

    try: import your_module except: this_folder = os.path.split(__file__)[0] sys.path.append(this_folder) import your_module
    Geosoft logo
  • I don't care developing in a single file, as it can be easily managed with PyCharms, but I am concerned about the final delivery. For commercial applications, I would like to protect the source code using applications as pyinstaller or py2exe.
  • To follow the previous post, I have been able to install my AEM python application linked to a Geosoft database via the GX API using PyInstaller. However, I had to copy manually Geosoft package in the dist directory.
This discussion has been closed.