Creating an executable file from a Python script

Hi, I wrote a Python script to calculate the time decay constant for time-domain EM data, and it works well. But when I build an executable file from the Python script using cx_Freeze, I can't run the program. I get an Python error of "File NotFoundError" (attached image) caused by a file named "library.zip\geosoft\pkg_info.json".
I'd really appreciate it if anyone could help me with this.

Regards
Omid

Comments

  • Based on the error message, you just need to place pkg_info.json in your ...\library.zip\geosoft\ folder. You will find a copy here:

    https://github.com/GeosoftInc/gxpy/blob/9.4/geosoft/pkg_info.json
    Geosoft logo
  • Hi,

    Since cx_Freeze by default only embeds the Python files you will likely need to follow these instructions to either find the files elsewhere in relation to your executable or embed them using Qt resources:

    https://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files

    You will also probably need to place the dlls, geosoft.key file and pyd modules in the geosoft\gxapi directory next to your exe.

    Disclaimer; I have not actually attempted this, but I'm pretty sure this should work.

    Cheers,
    Jacques

  • Thanks for your responses. @IanMacLeod : copy/paste the pkg_info.json didn't solve the problem. Now, I'm trying @JacquesBeaurain 's solution. I had read that article, but I couldn't understand where I should paste the code : def find_data_file(filename): ..... .
    I assume it should be in the setup.py file (the file that executes cx_Freeze). Is there any modification that should be made to the init.py for geosoft or the code: def find_data_file(filename): ?

    Regards
    O,
  • If it is only pkg_info.json, you can also modify __init__.py to set the version variable yourself.

    I suspect this may just move you on to the next problem, so as Jacques suggest, dig into the cx_Freeze docs to better understand how it packages resources. I can't help much there.
    Geosoft logo
This discussion has been closed.