我正在使用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()调用,但我不知道将其添加到哪里。
任何帮助都将不胜感激。
发布于 2018-12-17 20:34:15
引用multiprocessing.freeze_support()的documentation
One需要直接在主模块的
if __name__ == '__main__'行之后调用此函数。例如:
从多进程导入进程中,打印定义f():freeze_support (‘hello world!')如果进程‘__name__’:freeze_support() == (target=f).start()
因此,您需要在使用pandas-profiling的脚本的if __name__ == '__main__'行之后直接调用此函数。
如果脚本中没有这样的行:在脚本的第一个顶层代码行之前添加此行,并缩进整个脚本顶层代码,使其属于if块。请参阅What does if __name__ == "__main__": do?
另请参阅Python multiprocessing throws error with argparse and pyinstaller和where to put freeze_support() in a Python script?
https://stackoverflow.com/questions/53814351
复制相似问题