pyinstaller打包报错(qt-material)

在程序中,用到了qt-material库,IDE中一切正常,使用pyinstaller打包时,报错如下:

报错说是Path没有home属性,经过查找,找到了qt-material安装包resource目录下有一个generate.py文件,在文件中使用了pathlib库,源文件代码如下,这时候把Path.home()一行注释掉,写自己用户的家目录即可,他会到家目录下的.qt-material获取文件,注意,不是每台电脑都会出现这个问题,出现问题后按照说明修改就好

第二种解决办法就是,程序打包完成后,将qt-material目录中的文件手动拷贝到打包后的文件的根目录也可以,拷贝的资源如下,放在qt-material目录下即可

pyinstaller打包报错(qt-material)_第1张图片

 

discover_hook_directories: Failed to process hook entry point 'hook-dirs = qt_material:get_hook_dirs': type object 'Path' has no attribute 'home'

import os
import shutil
from pathlib import Path

HOME = Path.home()
RESOURCES_PATH = os.path.join(HOME, '.qt_material')


########################################################################
class ResourseGenerator:
    """"""

    # ----------------------------------------------------------------------
    def __init__(self, primary, secondary, disabled, source, parent='theme'):
        """Constructor"""

        if parent.startswith('/'):
            self.index = parent
        if parent.startswith('.'):
            self.index = parent[1:]
        else:
            self.index = os.path.join(RESOURCES_PATH, parent)

        self.contex = [
            (os.path.join(self.index, 'disabled'), disabled),
            (os.path.join(self.index, 'primary'), primary),
        ]

        self.source = source
        self.secondary = secondary

        for folder, _ in self.contex:
            shutil.rmtree(folder, ignore_errors=True)
            os.makedirs(folder, exist_ok=True)

    # ----------------------------------------------------------------------

    def generate(self):
        """"""
        for icon in os.listdir(self.source):
            if not icon.endswith('.svg'):
                continue

            with open(os.path.join(self.source, icon), 'r') as file_input:
                content_original = file_input.read()

                for folder, color in self.contex:
                    new_content = self.replace_color(content_original, color)
                    new_content = self.replace_color(
                        new_content, self.secondary, '#ff0000')

                    file_to_write = os.path.join(folder, icon)
                    with open(file_to_write, 'w') as file_output:
                        file_output.write(new_content)

    # ----------------------------------------------------------------------
    def replace_color(self, content, replace, color='#0000ff'):
        """"""
        colors = [color] + [''.join(list(color)[:i] +
                                    ['\\\n'] + list(color)[i:]) for i in range(1, 7)]
        for c in colors:
            content = content.replace(c, replace)

        replace = '#ffffff00'
        color = '#000000'
        colors = [color] + [''.join(list(color)[:i] +
                                    ['\\\n'] + list(color)[i:]) for i in range(1, 7)]
        for c in colors:
            content = content.replace(c, replace)

        return content

你可能感兴趣的:(PyQt5,pyinstaller,pyinstaller,PyQt5)