Search code examples
pythonpython-3.xplotlycx-freeze

cx_freeze error with plotly, Python 3.6


I'm having a problem using Anaconda 3, plotly and cx_freeze to generate an executable. Maybe you guys can enlighten my mind. I can generate the .exe but when I run it I get this:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-            
packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\ProgramData\Anaconda3\lib\site-
packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "main.py", line 15, in <module>
  File "C:\Users\a\Documents\b\c\plot_3d.py", line 
1, in <module>
    import plotly as py
  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\__init__.py", line 
31, in <module>
    from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, 
tools,
  File "C:\ProgramData\Anaconda3\lib\site-
packages\plotly\graph_objs\__init__.py", line 14, in <module>
    from plotly.graph_objs.graph_objs import *  # this is protected with 
__all__
  File "C:\ProgramData\Anaconda3\lib\site-
packages\plotly\graph_objs\graph_objs.py", line 34, in <module>
    from plotly import exceptions, graph_reference
  File "C:\ProgramData\Anaconda3\lib\site-
packages\plotly\graph_reference.py", line 9, in <module>
    from pkg_resources import resource_string
ModuleNotFoundError: No module named 'pkg_resources'

Looks like I'm having problem with plotly. After searching for a while I still couldn't fin a solution. This is my setup.py:

import sys

kwargs = {"name": "x",
          "version": "1.2",
          "author": "x",
          "author_email": "x",
          "description": "x",
          "zip_safe": False
          }

try:
    if sys.argv[1] == "build":
        import os
        from setuptools import find_packages
        from cx_Freeze import setup, Executable

        os.environ["TCL_LIBRARY"] = r"C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
        os.environ["TK_LIBRARY"] = r"C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"

        kwargs["options"] = {
            "build_exe": {
                "packages": find_packages() + ["os", "numpy", "plotly"],
                "includes": ["numpy", "plotly"],
        }
    }
    kwargs["executables"] = [Executable(r"main.py", base="console")]

    setup(**kwargs)
except Exception as e:
    print(e)

I have tried this solution without success, any suggestion? Thanks.


Solution

  • The solution was to include every package in:

    "includes": ["numpy", "plotly", "pkg_resources", "appdirs", "packaging.specifiers", "packaging.requirements"]