Why is pydot unable to find GraphViz's executables in Windows 8?

做~自己de王妃 提交于 2019-11-26 07:29:45

问题


I have GraphViz 2.32 installed in Windows 8 and have added C:\\Program Files (x86)\\Graphviz2.32\\bin to the System PATH variable. Still pydot is unable to find its executables.

Traceback (most recent call last):
  File \"<pyshell#26>\", line 1, in <module>
    graph.write_png(\'example1_graph.png\')
  File \"build\\bdist.win32\\egg\\pydot.py\", line 1809, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
  File \"build\\bdist.win32\\egg\\pydot.py\", line 1911, in write
    dot_fd.write(self.create(prog, format))
  File \"build\\bdist.win32\\egg\\pydot.py\", line 1953, in create
    \'GraphViz\\\'s executables not found\' )
InvocationException: GraphViz\'s executables not found

I found this https://code.google.com/p/pydot/issues/detail?id=65 but am unable to get the problem solved.


回答1:


The problem is that the path to GraphViz was not found by the pydot module as shown in the traceback:

'GraphViz\'s executables not found'

I solved this problem on my windows 7 machine by adding the GraphViz bin directory to my computer's PATH. Then restarting my python IDE to use the updated path.

  1. Install GraphViz if you haven't already (I used the MSI download)
  2. Get the path for gvedit.exe (for me it was "C:\Program Files (x86)\Graphviz2.34\bin\")
  3. Add this path to the computer's PATH
  4. One way to get to environment settings to set your path is to click on each of these button/menu options: start->computer->system properties->advanced settings->environment variables
  5. Click Edit User path
  6. Add this string to the end of your Variable value list (including semicolon): ;C:\Program Files (x86)\Graphviz2.34\bin
  7. Click OK
  8. Restart your Python IDE



回答2:


On Mac brew install graphviz solved the problem for me.




回答3:


This happened because I had installed graphviz after I had installed pydot. Hence, pydot wasn't able to find it. Reinstalling it in the correct order solved the problem.




回答4:


in my case answer from Sadik pydot and graphviz error: Couldn't import dot_parser, loading of dot files will not be possible worked for me on Ubuntu 12.04.5 LTS

sudo apt-get install python-pydot




回答5:


I tried adding PATH via Control Panel, but restarting the command prompt is also needed. The following also works for updating the path in a Notebook session without exiting:

import os     

os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'



回答6:


You need to install from Graphviz and then just add the path of folder where you installed Graphviz and its bin directory to system environments path.




回答7:


For windows 8.1 & python 2.7 , I fixed the problem by following below steps

1 . Download and install graphviz-2.38.msi https://graphviz.gitlab.io/_pages/Download/Download_windows.html

2 . Set the path variable

Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit add 'C:\Program Files (x86)\Graphviz2.38\bin'

  1. Restart your currently running application that requires the path



回答8:


Add dot.exe to your path. right click my computer > advanced system settings > environment variables > high light 'path' > edit then append everything in the quotes to path ";C:\Program Files (x86)\Graphviz2.34\bin\" depending on where you installed Graphviz ofcourse.Then restart the python shell and type.

import pydot pydot.find_graphviz() Make sure there is a slash after 'bin' so it gets everything from inside the folder, I tried with out the slash and the above code returned nothing, however after adding the slash it returned the graphviz executables it needed and their paths.




回答9:


I'm working on Windows 10 with Anaconda 3.6.5. I have not admin rights, so if someone is under the circumstances like me this solution works perfectly.

The path for my graphviz is looks C:\Users\User_Name\AppData\Local\Continuum\anaconda3\Library\bin\graphviz

In Spyder or in Jupyter type the following:

import os os.environ['PATH'].split(os.pathsep) This will lists all the path in you environment. Take a look to them, if your graphviz path is not here, then go find it and copy the path, like above in my example. Then type the following: os.environ['PATH'] += os.pathsep + 'C:\\Users\\User_Name\\AppData\\Local\\Continuum\\anaconda3\\Library\\bin\\graphviz'

That's all, but note that you have to run these command every time if you restart kernel




回答10:


For me: (Win10, Anaconda3) Make sure you have done "conda install graphviz"

I have to add to the PATH: C:\Users\username\Anaconda3\Library\bin\graphviz

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

MAKE SURE TO RESTART YOUR IDE AFTER THIS. It should work




回答11:


In Windows, even after installing graphviz-2.38.msi, you can add your own path in pydot.py (found under site-package folder)

 if os.sys.platform == 'win32':

    # Try and work out the equivalent of "C:\Program Files" on this
    # machine (might be on drive D:, or in a different language)
    #

    if os.environ.has_key('PROGRAMFILES'):

        # Note, we could also use the win32api to get this
        # information, but win32api may not be installed.

        path = os.path.join(os.environ['PROGRAMFILES'], 'ATT', 'GraphViz', 'bin')

    else:

        #Just in case, try the default...
        path = r"C:\PYTHON27\GraphViz\bin"  # add here.



回答12:


I too had the same issue and I finally resolved it by having a look at the library.

The library considers making the path set as C:\Program Files\ATT\Graphviz\bin but by default Graphviz is installed to C:\Program Files(x86)\Graphviz undergoing the 32-bit criteria hence the pydot fails in getting the required path. Simply shift the directory as required by the script and you're good to go.

P.S.:- Consider making the equivalent changes to the Environmnet Variable.

P.S.S:- Also check if Graphviz is directly under Program Files(x86) or under ATT.




回答13:


I am running a Windows 10 machine and had some problems, too. I installed graphviz via msi installer. Adding via System settings did not work for me.

I removed the installation with the msi and used chocolatey, a windows package manager. Removing the installed version is necessary, otherwise chocolatey won't install.

Now it runs fine. I would recommend doing it this way.




回答14:


Here is what I did for the above mentioned problem. I'm using windows 10 os and python 3.6.5

  1. Install PIP by clicking here

  2. open command prompt and type command "pip install graphviz"

  3. go to my computer(this pc) and search with the keyword "graphviz"

  4. open the graphviz folder and copy its path and save it in notepad

  5. In graphviz look for the bin folder and copy the folder by right click of your mouse

  6. now again head back to my computer and search for "pydotplus"

  7. a folder named pydotplus is displayed. Open it and paste the copy of bin folder (of Graphviz) that you copied earlier

  8. head to control panel>system and security> system settings> advanced settings> environmental variables> add new path

  9. add the path that you copied in notepad and click a series of "ok"

that's it now you can enjoy using graphviz




回答15:


install Graphviz here and add its bin path solved my problem

https://graphviz.gitlab.io/_pages/Download/Download_windows.html

pip install Graphviz itself seems inadequate




回答16:


Some things to know about graphviz:

  1. graphviz is not only a python module, it's also a standalone program. I believe you need both to make graphviz to work.
  2. The standalone graphviz program was originally developed by AT&T, open sourced, then abandoned. The current maintainers of the package forgot to include Windows registry entries so Python can find the program executable.
  3. Line 620 of pydotplus\graphviz.py includes a backup path to look for graphviz if it isn't found in the registry. It uses the old ATT file path. Update the file path to what is on your machine (you will need to have administrator privileges) and graphviz should work with pydotplus.

Example:

# Just in case, try the default... path = r"C:\Program Files (x86)\Graphviz2.38\bin"




回答17:


In "pydot.py" (located in ...\Anaconda3\Lib\site-packages), replace:

def get_executable_extension():
    # type: () -> str
    if is_windows():
        return '.bat' if is_anacoda() else '.exe'
    else:
        return ''

with:

def get_executable_extension():
    # type: () -> str
    if is_windows():
        return '.exe'
    else:
        return ''

There does not seem to be any eason to add ".bat" when the system is "Windows/Anaconda" vs "Windows" and there may be no ".bat" associated with the ".exe". This seems better than adding a ".bat" for every executable pydot calls...




回答18:


I had this issue and noticed that it was printing my PATH with two sets of double-quotes. I worked around the problem by adding the following to Line 1959 of:

C:\Anaconda\Lib\site-packages\pydot.py

self.progs[prog] = os.path.normpath(self.progs[prog][1:-1])

Obviously not the best fix but it got me through the day.




回答19:


I found a manual solution: sudo apt-get install graphviz

graph.write('test.dot') dot -Tps test.dot -o outfile.ps

You can the files here: https://github.com/jecs89/LearningEveryDay/tree/master/GP




回答20:


Tried all installation sequence as described in all solutions/posting/blogs, finally realized anaconda was not able to read the Environment variables. Closed Anaconda and Spyder. Then opened Anaconda in Administrator mode (on Windows 64 bit OS machine) and then opened Spyder. Script worked fine with PYDOT calls.




回答21:


I am not using a windows machine, I am on a linux platform. I ran across this executable-not-found issue in the context of using the python package pyAgrum for plotting bayesian networks. pyAgrum uses graphviz to plot the networks. I installed pyagrum and graphviz using the anaconda platform in a python 3.6.4 environment (i.e. conda install <package name>).

I found the executables in /conda/envs/<environment name>/bin directory. So, it was just a matter of getting my notebook kernel to find them.

If you import os, use the command os.environ['PATH'].split(os.pathsep) to see the executable paths in which your environment is looking. If the path containing your graphviz executables isn't in there, you can add it by doing the following: os.environ['PATH'] += os.pathsep + <path to executables>.

I imagine this solution will work outside of my context. The main downside to this solution is that you need to do it every time you restart the kernel.




回答22:


you can use pydotplus instead of pydot.then follow the belows:

First, find C:\Users\zhangqianyuan\AppData\Local\Programs\Python\Python36\Lib\site-packages\pydotplus

Second, open graphviz.py

Third, find line 1925 - line 1972, find the function def create(self, prog=None, format='ps'):

Final, in the function:

  1. 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])
        )
    
  2. between the two blocks add this(Your Graphviz's executable path):

    self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"

  3. 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])
        )
    
  4. save the changed file then you can run it successfully.

  5. you'd better save it as bmp file because png file will not work.




回答23:


If you dont want to mess around with path variables (e.g. if you are no admin) and if you are working on windows, you can do the following which solved the problem for me.

Open graphviz.py (likely located in ...Anaconda\pkgs\graphviz***\Library\bin) in an editor. If you cant find it you might be able to open it via the error message.

Go to the fuction __find_executables and replace:

elif os.path.exists(os.path.join(path, prg + '.exe')):
   if was_quoted:
      progs[prg] = '"' + os.path.join(path, prg + '.exe') + '"'
   else:
      progs[prg] = os.path.join(path, prg + '.exe')

with

elif os.path.exists(os.path.join(path, prg + '.bat')):
   if was_quoted:
      progs[prg] = '"' + os.path.join(path, prg + '.bat') + '"'
   else:
      progs[prg] = os.path.join(path, prg + '.bat')



回答24:


The solution is easy, you just need to download and install the Graphviz, from here.

Then set the path variable to the bin directory, in my case it was C:\Program Files (x86)\Graphviz2.38\bin. Last, do the conda install python-graphviz and it should work fine.




回答25:


On Anaconda distro, pip install did not work. I did a pip uninstall graphviz, pip uninstall pydot, and then I did conda install graphviz and then conda install pydot, in this order, and then it worked!



来源:https://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!