10

I am compiling my current program using pyinstaller and it seems to not be able to handle all required files in plotly. It runs fine on its own, and without plotly it can compile and run as well.

It seems be to failing to find a file "default-schema.json" that I cannot even locate anywhere on my drive.


Traceback (most recent call last): File "comdty_runtime.py", line 17, in File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "d:\users\ktehrani\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "actual_vs_mai.py", line 12, in File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "d:\users\ktehrani\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "site-packages\plotly__init__.py", line 31, in File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked
File "", line 1161, in _load_backward_compatible File "d:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "site-packages\plotly\graph_objs__init__.py", line 14, in
File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "d:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "site-packages\plotly\graph_objs\graph_objs.py", line 34, in File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "d:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "site-packages\plotly\graph_reference.py", line 578, in
File "site-packages\plotly\graph_reference.py", line 70, in get_graph_referenc e File "site-packages\setuptools-27.2.0-py3.4.egg\pkg_resources__init__.py", li ne 1215, in resource_string File "site-packages\setuptools-27.2.0-py3.4.egg\pkg_resources__init__.py", li ne 1457, in get_resource_string File "site-packages\setuptools-27.2.0-py3.4.egg\pkg_resources__init__.py", li ne 1530, in _get File "d:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 474, in get_data with open(path, 'rb') as fp: FileNotFoundError: [Errno 2] No such file or directory: 'H:\Python\Commodity_M AI_Trade_List\Code\dist\comdty_runtime\plotly\package_data\default-schema. json' Failed to execute script comdty_runtime

k-war
  • 540
  • 3
  • 15

5 Answers5

16

I came across the same problem, and worked my way through the pyinstaller documentation to find out what to do:

pyinstaller creates a .spec file with the same name as your .py file. under a = Analysis, you will find datas = []

a = Analysis(['graphic_interface.py'],
             pathex=[xxx],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

there you add the path for plotly. a relative path didn't work for me, so I set an absolute path

datas=[('C:\\Users\\Me\\PycharmProjects\\Project\\venv\\Lib\\site-packages\\plotly\\', 'plotly')],

now you have to use the spec file when running pyinstaller

pyinstaller myproject.spec myproject.py

you dont need to worry about other commands like oneFile etc, because they are already saved in the .spec file

Isajah
  • 176
  • 1
  • 3
7

You can still use the one file option, just make a .spec file for pyinstaller and include the needed plotly directories in datas like so:

...

datas=[('(...)/Python/Python36-32/Lib/site-packages/plotly/', './plotly/')],

...

code4days
  • 591
  • 3
  • 8
  • 16
5


it's seem like plotly isn't fully supported by PyInstaller.
I used an work around solution that worked for me.

  1. Don't use the one file option
  2. Completely copy the plotly package(for me it was Lib\site-packages\plotly) for the python installation directory into the /dist/{exe name}/ directory
Cfir TSabari
  • 372
  • 3
  • 13
4

This might not solve your issue but it solved my issues with Plotly maps. I put this code into my .spec file and was able to run Plotly charts after going through PyInstaller. Could not get my maps to show and was getting error messages.

File "<frozen importlib._bootstrap>"
ModuleNotFoundError: No module named 'plotly.validators.choropleth' pyinstaller

Now it works using the below:

# -*- mode: python ; coding: utf-8 -*-

import sys
sys.setrecursionlimit(5000)

block_cipher = None


a = Analysis(['napdgui.py'],
             pathex=['C:\\Users\\USERNAME\\Desktop\\Python\\NA\\naguiv1'],
             binaries=[],
             datas=[('C:\\Users\\USERNAME\\Anaconda3\\Lib\\site-packages\\plotly\\', 'plotly'),
                ],
             hiddenimports=['pkg_resources.py2_warn', 'app.urls'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='Tool v08122020',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='Analysis Tool v081320')
0range
  • 2,088
  • 1
  • 24
  • 32
Sandy
  • 71
  • 3
0

Before using pyinstaller, make sure that the imports that you are using in your program are specifically listed in the requirements file.

pip freeze->requirements.txt quickly creates a requirements file in your program.

I am not sure if this is the solution? I had similar issues that seem to go away once I updated the requirements file then making an executable.

Optimho
  • 1
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 27 '21 at 19:13
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 27 '21 at 20:56