收到notimplementederror:无法针对未注册的加载器类型执行此操作 [英] Getting notimplementederror: can't perform this operation for unregistered loader type

查看:144
本文介绍了收到notimplementederror:无法针对未注册的加载器类型执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个Windows应用程序,用于使用Pandas数据框比较两个Excel工作表.我使用dataframe.stlye.apply突出显示了一些基于数据的具有不同颜色的列,并将其导出到新的Excel文件中.另外,我已经使用pyinstaller将.py转换为.exe.

I have built a windows application for comparing two Excel sheets using Pandas dataframe. I used dataframe.stlye.apply to highlight some columns with different colors based on data and exporting it into a new Excel file. Also, I have used pyinstaller for converting .py into .exe.

代码段- save_op_file函数用于应用样式并保存到excel中.

def save_op_file(df):
    save_path = filedialog.asksaveasfilename(defaultextension='xlsx')
    writer = pd.ExcelWriter(save_path, engine='xlsxwriter')

    df1 = ''
    item_count = 0
    for items in changes:
        pos_count = 0
        for pos in items:
            if item_count == 0 and pos_count == 0:
                df1 = df.style.apply(write_style_yellow, row_idx=pos[0], col_idx=pos[1], axis=None)
            else:
                if pos_count == 0:
                    df1 = df1.apply(write_style_yellow, row_idx=pos[0], col_idx=pos[1], axis= None)
                else:
                    df1 = df1.apply(write_style_red, row_idx=pos[0], col_idx=pos[1], axis= None)

            item_count += 1
            pos_count += 1
            print('df1:')
            print(df1)
            df1.to_excel(writer, sheet_name='Sheet1', index=False)
    writer.save()
def write_style_yellow(x, row_idx, col_idx):
    color = 'background-color: yellow'
    df_styler = pd.DataFrame('', index=x.index, columns=x.columns)
    df_styler.iloc[row_idx,col_idx] = color
    return df_styler
def write_style_red(x,row_idx,col_idx):
    color = 'background-color: red'
    df_styler = pd.DataFrame('', index=x.index, columns=x.columns)
    df_styler.iloc[row_idx,col_idx] = color
    return df_styler

现在,当我运行我的应用程序时,它会引发此错误-

Now, when I am running my application, it is throwing this error -

    Exception in Tkinter callback 
       Traceback (most recent call last): 
         File "tkinter\ init .py", line 1883, in _call_ 
         File "Excel.py", line 199, in <lambda> 
         File "Excel.py", line 217, in save_op_file 
         File "pandas\core\frame.py", line 836, in style 
         File "<frozen importlib._bootstrap>", line 991, in _find_and_load 
         File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked 
         File "<frozen importlib._bootstrap>", line 671, in _load_unlocked 
         File "c:\users\asus\pycharmprojects\myproject\venv\lib\site- 
        packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module 
          exec(bytecode, module. dict ) 
         File "pandas\io\formats\style.py", line 51, in <module> 
         File "pandas\io\formats\style.py", line 124, in Styler 
         File "jinja2\environment.py", line 883, in get_template 
         File "jinja2\environment.py", line 857, in _load_template 
         File "jinja2\loaders.py", line 115, in load File "jinja2\loaders.py", line 248, in get_source 
         File "pkg_resources\ init .py", line 1404, in has_resource 
         File "pkg_resources\ init .py", line 1473, in _has 
         NotlmplementedError: Can't perform this operation for unregistered loader type*

您能帮我解决这个问题吗? 预先感谢.

Could you please help me in resolving this issue. Thanks in advance.

推荐答案

我能够解决此问题.

发生此问题是因为pkg_resources与pyinstaller不兼容,而jinja2正在使用pkg_resources.

This issue is occuring because pkg_resources is not compatible with pyinstaller and jinja2 is using pkg_resources.

解决方案:

我使用cx_Freeze而不是pyinstaller将.py文件转换为.exe,它对我来说很好用.您可以参考cx_Freeze-如何将Python的.py转换为.exe?

I used cx_Freeze instead of pyinstaller for converting .py file into .exe, and it worked fine for me. You can refer this for cx_Freeze- How can I convert a .py to .exe for Python?

使用cx_Freeze的参考-

Reference to use cx_Freeze -

如何将.py转换为. exe for Python?

谢谢!

这篇关于收到notimplementederror:无法针对未注册的加载器类型执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆