1

I have a python script which contains:

tempBook = temp.Workbooks.Open("c:\users\CNAME\desktop\Template.xlsx")

Everything works fine but when I create a .exe of my script the Template.xlsx is not included in its 'build' folder, it needs Template.xlsx to be present on the desktop. I want to make a portable exe.

Is there any way so that it can be included in the build, and make a standalone exe without any dependencies?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user2211059
  • 43
  • 1
  • 4

1 Answers1

3

You need to move the file to your package, and list it in your setup.py:

setup(
    # ...
    data_files = [('', ['Tempate.xlsx',])],
)

See the data_files documentation for py2exe, which includes a utility function for automating adding data files.

The files will be added in your app root. From your main script, you can determine your app root by using:

import os

try:
    approot = os.path.dirname(os.path.abspath(__file__))
except NameError:  # We are the main py2exe script, not a module
    import sys
    approot = os.path.dirname(os.path.abspath(sys.argv[0]))
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343