Jonathan Nye Jonathan Nye - 2 years ago 260
Python Question

Cx_Freeze and Plotly

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\", line 284, in p
File "C:\Python34\lib\site-packages\plotly\offline\", line 48, in ge
plotlyjs = resource_string('plotly', path).decode('utf-8')
File "C:\Python34\lib\site-packages\pkg_resources\", line 1184, in
self, resource_name
File "C:\Python34\lib\site-packages\pkg_resources\", line 1457, in
return self._get(self._fn(self.module_path, resource_name))
File "C:\Python34\lib\site-packages\pkg_resources\", line 1535, in
return self.loader.get_data(path)
OSError: [Errno 0] Error: 'plotly\\offline\\plotly.min.js'

I have tried including pkg_resources in the 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 file, but it is included in the path outside of the I can't seem to find a way to add the files to the file in the

Thanks for your help.

Answer Source

Ok, I figured it out. You can include the files in the First create the list of files to include, like in the normal includes. python_dir is the path to your python directory that contains the files.

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')]

Then in your setup:

      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}},

This will include the files inside the and will not include them like the typical external files to include.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download