0

I have created an application for windows using pythons cx_freeze module. The application runs the openpyxl module which runs fine for the script but when frozen it fails to find the .constants.json files. The following error is displayed. FileNotFoundError: [Errno 2] No such file or directory: 'C:....\exe.win-amd64-3.4\library.zip\openpyxl.constants.json'

I have found a fix for this (https://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files) detailed below :

def find_data_file(filename):
if getattr(sys, 'frozen', False):
    # The application is frozen
    datadir = os.path.dirname(sys.executable)
else:
    # The application is not frozen
    # Change this bit to match where you store your data files:
    datadir = os.path.dirname(__file__)

return os.path.join(datadir, filename)

The question I have is where do I paste this code? Does it go in the setup.py file? Or somewhere else?

CBell
  • 1
  • 2
  • You may have to modify the openpyxl code so that it uses that function to search for its data file. It looks like openpyxl isn't expecting to be loaded from a zip file. – Thomas K Jan 31 '16 at 11:16
  • 1
    Thanks Thomas yes I edited the _init_.py file for openpyxl and put the .constants.json file in as an included file to the setup.py file and it worked a treat. – CBell Feb 04 '16 at 12:55

0 Answers0