PyGame NotImplementedError

前端 未结 1 1620
感动是毒
感动是毒 2021-01-27 08:31

I made a pygame application using PyInstaller but for some reason when I open it it raises the NotImplementedError, if found out that this error is being raised in the _has func

相关标签:
1条回答
  • 2021-01-27 09:10

    I finally figured it out, I had to save the ttf file in the same directory as the code. This works for compiling the application into a folder, but for one file you have to change the code.

    def rp(relative_path):
        """ Get absolute path to resource, works for dev and for PyInstaller """
        try:
            # PyInstaller creates a temp folder and stores path in _MEIPASS
            base_path = sys._MEIPASS
        except Exception:
            base_path = os.path.abspath(".")
    
        return os.path.join(base_path, relative_path)
    

    upon adding this function you must call it with the name and extension of the file you wish to use, like:

    rp('freesansbold.ttf')
    

    to initialize the font just do this:

    Font = p.font.Font(rp('freesansbold.ttf'), 12) #initializes font
    

    it works to same for the images I was using too, but i had the take them out to the Sprites folder and package each picture individually with the program. Here's the spec file for Pyinstaller:

    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(['DVD.py'],
                 pathex=['C:\\Users\\Kaden\\Desktop\\dvd builds'],
                 binaries=[],
                 datas=[('./w.png', '.'), ('./b.png', '.'), ('./g.png', '.'), ('./o.png', '.'), ('./p.png', '.'), ('./p2.png', '.'), ('./y.png', '.'), ('./freesansbold.ttf', '.')],
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              [],
              name='DVD',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              runtime_tmpdir=None,
              console=False , icon='icon.ico')
    

    then just call pyinstaller like you usually would:

    pyinstaller DVD.spec
    
    0 讨论(0)
提交回复
热议问题