cx_Freeze的熊猫分析问题

时间:2018-12-17 11:31:13

标签: python pandas cx-freeze

我正在使用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()调用,但是我无法找出将其添加到何处。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

引用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()

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

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

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