OMG! This PyInstaller really confused me for a bit. If my previous post sounds a little “ranty”, sorry about that.. Anyways, for anyone trying to include a file in a –onefile PyInstaller package this worked for me:
Include this in your .py script:
filename = 'myfilesname.type'
if hasattr(sys, '_MEIPASS'):
# PyInstaller >= 1.6
filename = join(sys._MEIPASS, filename)
elif '_MEIPASS2' in environ:
# PyInstaller < 1.6 (tested on 1.5 only)
filename = join(environ['_MEIPASS2'], filename)
filename = join(dirname(sys.argv), filename)
credit to someone online whose name I don’t remember.. (sorry it’s late and I’m exhausted!)
Then, if you’re using PyInstaller2.0, in cmd, from the pyinstaller-2.0 dir, you can run
pyinstaller.py --onefile myscriptsname.py
That will create a myscriptsname.spec file in the pyinstaller-2.0 dir. It will also create an exe, but that won’t work. It will be updated later. Now edit that .spec, and add the following a.datas line (remember datas, not data). I included a little extra in the .spec file just for reference.
a = Analysis(['ServerTimeTest_nograph.py'],
a.datas += [('myfilesname.type','C:\\path\\to\\my\\file\\myfilesname.type','DATA')]
pyz = PYZ(a.pure)
Now, back in cmd, run
pyinstaller.py --onefile myscriptsname.spec
This will update your .exe in the /dist dir.
Maybe there’s a better way, or a prettier way, but this worked for me!