Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphviz.backend.execute.ExecutableNotFound #357

Closed
ww-zhou11 opened this issue Dec 1, 2021 · 2 comments · Fixed by #358
Closed

graphviz.backend.execute.ExecutableNotFound #357

ww-zhou11 opened this issue Dec 1, 2021 · 2 comments · Fixed by #358

Comments

@ww-zhou11
Copy link

ww-zhou11 commented Dec 1, 2021

Describe the bug

  • Which hook/library isn't working?

  • I'm using hook-pygraphviz on a MacOS to pack my python coding, the package works well on my laptop, when I send the package to other users, it reported error code : graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH

  • Does the error get raised while building or when running?
    while running

To Reproduce

A minimal example file:

from foo import bar
bar.do_something()

PyInstaller command:

pyinstaller --hidden-import pkg_resources.py2_warn --hidden-import numpy.random.common --hidden-import numpy.random.bounded_integers --hidden-import numpy.random.entropy --hidden-import sklearn.utils._cython_blas --hidden-import sklearn.neighbors.typedefs --hidden-import sklearn.neighbors.quad_tree --hidden-import tensorflow.compiler.tf2tensorrt --hidden-import tensorflow.compiler.tf2tensorrt.ops --hidden-import sklearn.tree._utils --additional-hooks-dir /Users/xxxxxx --target-architecture x86_64 -F /Users/xxxxx

pyinstall test.py

Error:

Traceback (most recent call last):
Traceback (most recent call last):
  File "graphviz/backend/execute.py", line 85, in run_check
  File "subprocess.py", line 489, in run
  File "subprocess.py", line 854, in __init__
  File "subprocess.py", line 1702, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: PosixPath('dot')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "conan_app.py", line 475, in <module>
  File "conan_app.py", line 469, in main
  File "conan_app.py", line 294, in selected_unit
  File "conan_app.py", line 253, in dotting_w_timedelta
  File "graphviz/_tools.py", line 161, in wrapper
  File "graphviz/rendering.py", line 119, in render
  File "graphviz/_tools.py", line 161, in wrapper
  File "graphviz/backend/rendering.py", line 317, in render
  File "graphviz/backend/execute.py", line 88, in run_check
graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH
[17270] Failed to execute script 'conan_app' due to unhandled exception!

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

   ...
SomeTypeOfError: Something went wrong

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 12.0.1
  • Python Version: python3.8.1
  • Version of pyinstaller-hooks-contrib: 2021.3
  • Version of PyInstaller 4.7

Additional context

Here is the logs during building..., I print out the binaries and datas, seems it is loaded correctly?

73823 INFO: Loading module hook 'hook-graphviz.py' from '/Users/xxxxxx

/usr/local/Cellar/graphviz/2.44.1/bin
/usr/local/Cellar/graphviz/2.44.1/lib/graphviz
[('/usr/local/Cellar/graphviz/2.44.1/bin/neato', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/dot', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/twopi', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/circo', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/fdp', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/nop', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/acyclic', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/gvpr', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/gvcolor', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/ccomps', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/sccmap', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/tred', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/sfdp', '.'), ('/usr/local/Cellar/graphviz/2.44.1/bin/unflatten', '.'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_quartz.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_visio.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_dot_layout.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_webp.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_webp.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_dot_layout.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_visio.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_neato_layout.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_core.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_pango.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_core.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_gd.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_pango.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_quartz.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_neato_layout.6.dylib', 'graphviz'), ('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/libgvplugin_gd.dylib', 'graphviz')]
[('/usr/local/Cellar/graphviz/2.44.1/lib/graphviz/config6', 'graphviz')]

@ww-zhou11 ww-zhou11 added the state:triage We're still figuring out how severe this issue is label Dec 1, 2021
@rokm
Copy link
Member

rokm commented Dec 3, 2021

It looks like pygraphviz is explicitly searching PATH for graphviz executables.

So as a quick work-around you need to ensure that sys._MEIPASS is added to PATH before you start using pygraphviz, for example by adding the following at the top of your program:

# Add sys._MEIPASS to PATH in a frozen application
import sys
if getattr(sys, 'frozen', False):
    import os
    path = os.environ.get('PATH')
    if path:
         path = path + os.pathsep + sys._MEIPASS
    else:
         path = sys._MEIPASS
    os.environ['PATH'] = path

from foo import bar
bar.do_something()

Long-term, this should be handled by a runtime hook that overrides pygraphviz' search behavior, which is what #358 does.

So as a quick work-around, you can also apply similar monkey-patching of pygraphviz.AGraph._which at the start of your program (in a frozen-application-specific codepath); or save the runtime hook from #358 to a file and use it with pyinstaller's --runtime-hook switch; or apply the corresponding patch from #358 to your pyinstaller-hooks-contrib installation.

@rokm rokm removed the state:triage We're still figuring out how severe this issue is label Dec 3, 2021
@bwoodsend
Copy link
Member

Although adding the root of the build to PATH is a bad idea on Windows because it mucks up DLL loading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants