Bundling data files with PyInstaller (--onefile)

前端 未结 13 1609
清歌不尽
清歌不尽 2020-11-21 13:28

I\'m trying to build a one-file EXE with PyInstaller which is to include an image and an icon. I cannot for the life of me get it to work with --onefile.

<
13条回答
  •  忘掉有多难
    2020-11-21 14:09

    Slight modification to the accepted answer.

    def resource_path(relative_path):
        """ Get absolute path to resource, works for dev and for PyInstaller """
        if hasattr(sys, '_MEIPASS'):
            return os.path.join(sys._MEIPASS, relative_path)
    
        return os.path.join(os.path.abspath("."), relative_path)
    

提交回复
热议问题