【问题标题】:pandas-profiling issues with cx_Freezecx_Freeze 的熊猫分析问题
【发布时间】:2018-12-17 11:31:13
【问题描述】:

我正在使用cx_freeze 将我的 Python 应用程序转换为 Windows 可执行文件。我在我的一个脚本中使用pandas-profiling 包。当我运行我的 exe 文件时,我收到以下错误:

    File "C:\Users\Ronnie\python3.6\Lib\site-packages\pandas_profiling\__init__.py", line 10, in <module>
    import pandas_profiling.templates as templates
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\pandas_profiling\templates.py", line 64, in <module>
    row_templates_dict = {'NUM': template('row_num'),
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\pandas_profiling\templates.py", line 60, in template
    return jinja2_env.get_template(templates[template_name], globals=globals)
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\jinja2\environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\jinja2\environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\jinja2\loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\jinja2\loaders.py", line 234, in get_source
    if not self.provider.has_resource(p):
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\pkg_resources\__init__.py", line 1396, in has_resource
    return self._has(self._fn(self.module_path, resource_name))
  File "C:\Users\Ronnie\python3.6\Lib\site-packages\pkg_resources\__init__.py", line 1449, in _has
    "Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type

如果我将pandas-profiling与exe文件放在同一目录中然后运行它,我会收到以下错误:

 error: unrecognized arguments: --multiprocessing-fork 1448

在寻找多处理错误的解决方案时,我发现pandas-profiling 在其脚本之一中使用multiprocessing,并且需要在该模块中调用multiprocessing.freeze_support(),但我不知道在哪里添加这个。

任何帮助将不胜感激。

【问题讨论】:

    标签: python pandas cx-freeze pandas-profiling


    【解决方案1】:

    引用multiprocessing.freeze_support()documentation

    需要在主模块的if __name__ == '__main__' 行之后直接调用此函数。例如:

    from multiprocessing import Process, freeze_support
    
    def f():
          print('hello world!')
    
    if __name__ == '__main__':
        freeze_support()
        Process(target=f).start()
    

    因此,您需要在使用 pandas-profiling 的脚本的 if __name__ == '__main__' 行之后直接调用此函数。

    如果您的脚本中没有这样的行:将此行添加到脚本的第一个顶级代码行之前,并将脚本的整个顶级代码缩进,使其属于if堵塞。见What does if __name__ == "__main__": do?

    另见Python multiprocessing throws error with argparse and pyinstallerwhere to put freeze_support() in a Python script?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-17
      • 2023-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-05
      • 2021-02-09
      • 2023-03-11
      相关资源
      最近更新 更多