0

I am trying to build an exe of an application that uses plotly using cx_freeze.

I have previously built the application using matplotlib but have switched the graphing over to plotly.

I can build the application but when I try to plot, I get the following error.

 url = py.plot(fig, filename='pandas-box-plot')

  File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 284, in p
lot
    get_plotlyjs(),
  File "C:\Python34\lib\site-packages\plotly\offline\offline.py", line 48, in ge
t_plotlyjs
    plotlyjs = resource_string('plotly', path).decode('utf-8')
  File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1184, in
resource_string
    self, resource_name
  File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1457, in
get_resource_string
    return self._get(self._fn(self.module_path, resource_name))
  File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1535, in
_get
    return self.loader.get_data(path)
OSError: [Errno 0] Error: 'plotly\\offline\\plotly.min.js'

I have tried including pkg_resources in the setup.py file and have also included the plotly.min.js in the PATH_to_exe\offline\plotly.min.js.

As far as I can tell the pkg_resources has the problem?

Edit: It seems like pkg_resources is looking for the file in the library.zip file, but it is included in the path outside of the library.zip. I can't seem to find a way to add the files to the library.zip file in the setup.py

Thanks for your help.

4

1 回答 1

0

好的,我想通了。您可以在 setup.py 中包含这些文件。首先创建要包含的文件列表,就像在正常包含中一样。python_dir 是包含文件的 python 目录的路径。

zip_includes = [('%s\Lib\site-packages\plotly\offline\plotly.min.js' % str(python_dir), 'plotly\offline\plotly.min.js'),
                ('%s\Lib\site-packages\plotly\widgets\graphWidget.js' % str(python_dir), 'plotly\widgets\graphWidget.js'),
                ('%s\Lib\site-packages\plotly\graph_reference\default-schema.json' % str(python_dir), 'plotly\graph_reference\default-schema.json')]

然后在您的设置中:

setup(name="Orion",
      version="1,
      author="Jonathan",
      description="Metering analysis tool",
      options={'build_exe': {'excludes': excludes, 'packages': packages, 'include_files': include_files, 'build_exe': "%s/build" % BASE_PATH, 'zip_includes': zip_includes}},
      executables=[compileTarget]
      )

这将包含 library.zip 中的文件,并且不会像要包含的典型外部文件那样包含它们。

于 2016-04-21T10:54:56.877 回答