Graphviz's executables are not found (Python 3.4)

后端 未结 26 1253
故里飘歌
故里飘歌 2020-11-29 05:00

I am running Python3.4 on Windows 7. I am trying to use the Python interface for graphviz. This is a script I intend to run:

from graphviz import Digraph
imp         


        
相关标签:
26条回答
  • 2020-11-29 05:50

    In my case (Win10, Anaconda3, Jupyter notebook) after "conda install graphviz" I have to add to the PATH: C:\Users\username\Anaconda3\Library\bin\graphviz

    To modify PATH goto Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

    0 讨论(0)
  • 2020-11-29 05:50

    I had the same issue with Windows 10.

    First, I installed graphviz-2.38.0 with the following command without any problem...

    install -c anaconda graphviz=2.38.0
    

    Second, I installed pydotplus with the following command without any problem...

    install -c conda-forge pydotplus
    

    After that, when I got to my step to visualize my decision tree had the following issue with {InvocationException: GraphViz's executables not found}...

    C:\Users\admin\Anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format)
       1958             if self.progs is None:
       1959                 raise InvocationException(
    -> 1960                     'GraphViz\'s executables not found')
       1961 
       1962         if prog not in self.progs:
    
    InvocationException: GraphViz's executables not found
    

    In my case, all I had to do to fix it is to put the environment path of the graphviz executables in my user PATH environment variable and this fixed it. Just make sure it is the path where YOUR.exe files are located :)

    C:\Users\admin\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz
    
    0 讨论(0)
  • 2020-11-29 05:52

    Please note that I am using windows 10. some of the following may or may not applicable for other versions of windows or operating systems:

    ** Note 2: **
    "the Graphviz bin file address on your system" can be C:\Program Files (x86)\Graphviz2.38\bin or any other path you installed Graphviz there.

    We have problem not only with Graphviz but also with other external EXE files we want to use in Jupyter.
    The reason is when jupyter wants to import a package it looks in working directory to find it and when it fails to find the package it returns such errors.
    What we can do is tackle this is as follows:
    1) check if the Graphviz is installed on your system and if not you can download and install it from:

    https://graphviz.gitlab.io/_pages/Download/Download_windows.html
    and then install it. When you installing Graphviz, keep in mind where (in which folder) you are installing it. If you see the above error when you use

    import graphviz
    

    then you have several options:

    2) you can call the .exe file in the ipynb via

    import os
    os.environ["PATH"] += os.pathsep + r'the Graphviz bin file address on your system'
    

    It is my experience that it is only works for the same ipynb that I am working with and every time that I open the notebook I need to call this lines of code.

    3) If you want the Jupyter where to find the exe file, you need to set environmenal path.
    In windows 10 you can do this going to:
    Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New
    and then add the "the Graphviz bin file address on your system" In windows 8 or lower go to :
    Control Panel > System and Security > System > Advanced System Settings > Environment Variables
    and then add the ;(semicolon) + "the Graphviz bin file address on your system" to the end of path string
    Note: remember to restart your machine.

    4) and even this does not work, define a variable going to:
    Control Panel > System and Security > System > Advanced System Settings > Environment Variables and then:

    Then define a variable as this:

    Remember to name the variable Graphviz. At last restart your PC and hope it works.

    0 讨论(0)
  • 2020-11-29 05:53

    when you add C:\Program Files (x86)\Graphviz2.38\bin to PATH, then you must close your IDE enviroment such as spyder and restart, you'll solve the "RuntimeError:make sure the Graphviz executables are on your systems' path"

    0 讨论(0)
  • 2020-11-29 05:53

    Please use pydotplus instead of pydot

    1. Find:C:\Users\zhangqianyuan\AppData\Local\Programs\Python\Python36\Lib\site-packages\pydotplus

    2. Open graphviz.py

    3. Find line 1925 - line 1972, find the function:

      def create(self, prog=None, format='ps'):
      
    4. In the function find:

      if prog not in self.progs:
          raise InvocationException(
              'GraphViz\'s executable "%s" not found' % prog)
      
      if not os.path.exists(self.progs[prog]) or \
              not os.path.isfile(self.progs[prog]):
          raise InvocationException(
              'GraphViz\'s executable "{}" is not'
              ' a file or doesn\'t exist'.format(self.progs[prog])
          )
      
    5. Between the two blocks add this(Your Graphviz's executable path):

        self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"`
      
    6. After adding the result is:

      if prog not in self.progs:
          raise InvocationException(
              'GraphViz\'s executable "%s" not found' % prog)
      
      self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"
      
      if not os.path.exists(self.progs[prog]) or \
              not os.path.isfile(self.progs[prog]):
          raise InvocationException(
              'GraphViz\'s executable "{}" is not'
              ' a file or doesn\'t exist'.format(self.progs[prog])
          )
      
    7. save the changed file then you can run it successfully.

    8. you'd better save it as bmp file because png file will not work. picture is here

    0 讨论(0)
  • 2020-11-29 05:53

    Try

    import os
    
    os.environ['PATH']=os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"
    
    0 讨论(0)
提交回复
热议问题