Quantcast

.exe file cannot find data files (No suche file or directory

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

.exe file cannot find data files (No suche file or directory

T.Nakamura
I have created a game application sample using PyGame and tried to generate one file .exe via PyInstaller. I have generated .exe file that seems like fine, but it cannot run it because of the error below:


# error on my command pronpt when running main.exe
C:\mygame\mygame\dist>main.exe
[Errno 2] No such file or directory: 'C:\\Users\\bggfr\\AppData\\Local\\Temp\\_MEI95~1\\item.data' IO Error ocarr.


The result of typing "pyi-archive_viewer" is like this and I can see "item.data" is properly combined with .exe file.


# pyi-archive_viewer main.exe
C:\mygame\mygame\dist>pyi-archive_viewer main.exe
 pos, length, uncompressed, iscompressed, type, name
[(0, 170, 234, 1, 'm', u'struct'),
 (170, 1136, 2480, 1, 'm', u'pyimod01_os_path'),
 (1306, 4196, 11036, 1, 'm', u'pyimod02_archive'),
 (5502, 5998, 17836, 1, 'm', u'pyimod03_importers'),
 (11500, 1589, 4450, 1, 's', u'pyiboot01_bootstrap'),
 (13089, 230, 313, 1, 's', u'pyi_rth_pkgres'),
...
 (4817215, 6585, 21321, 1, 'x', u'Include\\pyconfig.h')
 (4823800, 9999, 10925, 1, 'x', u'data\\font.png'),
 (4833799, 1059, 2231, 1, 'x', u'data\\item.data'),
 (4834858, 1009, 3952, 1, 'x', u'data\\kana2rect.dat'),
 (4835867, 753, 1454, 1, 'x', u'data\\kirito.data'),
 (4836620, 1843, 7439, 1, 'x', u'data\\mapchip.dat'),
 (4838463, 783, 1595, 1, 'x', u'data\\philia.data'),
 (4839246, 56, 51, 1, 'x', u'data\\save.data'),
 (4839302, 683, 1288, 1, 'x', u'data\\sinon.data'),
 (4839985, 684, 1295, 1, 'x', u'data\\siune.data'),
 (4840669, 2296, 7282, 1, 'x', u'data\\skill.data'),
 (4842965, 4967181, 9209540, 1, 'x', u'font\\msgothic.ttc'),
 (9810146, 489580, 489702, 1, 'x', u'image\\back_status.png'),
 (10299726, 61025, 61073, 1, 'x', u'image\\kirito.png'),
 (10360751, 890677, 899636, 1, 'x', u'image\\magic_circle.png'),
 (11251428, 60390, 60373, 1, 'x', u'image\\philia.png'),
 (11311818, 75259, 75228, 1, 'x', u'image\\sinon.png'),
 (11387077, 83961, 84035, 1, 'x', u'image\\siune.png'),
 (11471038, 1255741, 1255741, 0, 'z', u'out00-PYZ.pyz')]


this is my .spec file and I have made .exe file via this .spec file.

# main.spec

# -*- mode: python -*-
import sys

block_cipher = None

a = Analysis(['main.py'],
             pathex=['C:\\mygame\\mygame'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
Tree('C:/mygame/mygame/data',prefix='DATA'),
Tree('C:/mygame/mygame/font',prefix='FONT'),
Tree('C:/mygame/mygame/image',prefix='IMAGE'),
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='main',
          debug=False,
          strip=False,
          upx=True,
          console=True )


I'm sure that I need to use "_MEIPASS" when I read data files because the file path while running .exe file created by PyInstaller will be a temporary folder looking like above error(C:\\Users\\bggfr\\AppData\\Local\\Temp\\_MEI95~1).

I always use the function below where I need to read a data files(txt, img, font, etc...)


# a function that reads data files

    def resource_path(self, directory, filename):
        if hasattr(sys, "_MEIPASS"):
            return os.path.join(sys._MEIPASS, filename)
        return os.path.join(directory, filename)


Finally, I have used the latest version of PyInstaller explained in PyInstaller Web page 

# PyInstaller install command
pip install -e https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Does anyone can figure out what is wrong and how can I fix the problem?

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

.exe file cannot find data files (No suche file or directory

T.Nakamura
I'm very sorry, I just forgot to read file with resource_path function. Just I fixed it, .exe now does work.

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: .exe file cannot find data files (No suche file or directory

davecortesi
I am happy you found your small error. Your description of the problem was very clear, thank you.

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/d/optout.
Loading...