1

I have a python script which reads a large dictionary file which is stored as a .txt file. Now I want to make a single executable using py2exe. Currently, my setup looks like this:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

Mydata_files = [('.', ['dict_lookup.txt'])]


setup(console=['BladeHost.pyw'],
  options = {
    "py2exe": {
        'bundle_files': 1, #with this == 1, I have the weird CreateActCtx error msg
        'compressed': True,
        "dll_excludes": ["MSVCP90.dll", "gdiplus.dll"],

        }
    },
  zipfile = None,
  data_files=Mydata_files,
  )

This setup gives me the executable and the dict_lookup.txt in the dist folder. However, I do not want this stupid .txt file outside of the executable. I know I copy and paste this text file into a long string inside the python script but that will make my python script ugly.

So my question is, is there a way to setup py2exe so that this .txt file is built into the executable?

Thanks for any help.

foresightyj
  • 2,006
  • 2
  • 26
  • 40

1 Answers1

2

Putting it into a Python file as a string is actually the way things are most often done. If you have a look at the PyQt resource system for example, you will see that they embed any resource (images, sounds, etc...) as huge byte strings in some Python files that you should not modify afterwards.

Just make a separate Python file called resources.py or something like that if you want to keep your code clean. Then import the variables from that file.

Morwenn
  • 21,684
  • 12
  • 93
  • 152
  • Thanks for the quick reply. There must be no better solutions to this. I'll follow your suggestion then. – foresightyj May 02 '13 at 10:00
  • 2
    There may be a solution with `py2exe`. But it would not be that simple anyway. For example, [have a look at this question](http://stackoverflow.com/questions/1939883/py2exe-embed-static-files-in-exe-file-itself-and-access-them). – Morwenn May 02 '13 at 10:02
  • 1
    Thanks again. I used the Darren's solution in that thread and it worked out quite well. What a neat solution! – foresightyj May 03 '13 at 08:07