Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyinstaller fails with plotly

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

like image 290
k-war Avatar asked Sep 07 '17 15:09

k-war


3 Answers

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

like image 165
Isajah Avatar answered Oct 16 '22 09:10

Isajah


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

...

like image 7
code4days Avatar answered Oct 16 '22 08:10

code4days



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
like image 5
Cfir TSabari Avatar answered Oct 16 '22 09:10

Cfir TSabari