0

I'm using cx_freeze to convert my Python app to Windows executable file. I am using pandas-profiling package in one of my scripts. When I run my exe file I get the following error:

    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

And If I place the pandas-profiling in the same directory as the exe file and then run it, I get the following error:

 error: unrecognized arguments: --multiprocessing-fork 1448

While looking for a solution to the multiprocessing error, I found out that pandas-profiling is using multiprocessing in one of its scripts and there needs to be multiprocessing.freeze_support() call in that module but I can't figure out where to add this.

Any help would be appreciated.

Simon
  • 5,464
  • 6
  • 49
  • 85
Ronnie
  • 391
  • 2
  • 6
  • 19

1 Answers1

0

Quoting the documentation of multiprocessing.freeze_support():

One needs to call this function straight after the if __name__ == '__main__' line of the main module. For example:

from multiprocessing import Process, freeze_support

def f():
      print('hello world!')

if __name__ == '__main__':
    freeze_support()
    Process(target=f).start()

So you need to call this function straight after the if __name__ == '__main__' line of your script which uses pandas-profiling.

If you don't have such a line in your script: add this line before the first top-level code line of you script and indent the whole top-level code of your script so that it belongs to the if block. See What does if __name__ == "__main__": do?

See also Python multiprocessing throws error with argparse and pyinstaller and where to put freeze_support() in a Python script?

jpeg
  • 2,372
  • 4
  • 18
  • 31