pydot and graphviz error: Couldn't import dot_parser, loading of dot files will not be possible

后端 未结 14 1240
臣服心动
臣服心动 2020-11-28 01:15

When I run a very simple code with pydot

import pydot
graph = pydot.Dot(graph_type=\'graph\')

for i in range(3):

  edge = pydot.Edge(\"king\", \"lord%d\" %         


        
相关标签:
14条回答
  • 2020-11-28 02:07

    Answer for pydot >= 1.1:

    The incompatibility of (upstream) pydot has been fixed by 6dff94b3f1, and thus pydot >= 1.1 will be compatible with pyparsing >= 1.5.7.


    Answer applicable to pydot <= 1.0.28:

    For anyone else who comes across this, it is due to the changes in pyparsing from 1.x to the 2.x release. To install pydot using pip, first install the older version of pyparsing:

    pip install pyparsing==1.5.7
    pip install pydot==1.0.28
    

    If you did not install pyparsing using pip, but instead used setup.py, then have a look at this solution to uninstall the package. Thanks @qtips.

    0 讨论(0)
  • 2020-11-28 02:09

    I had the problem again and my above solution did not work. If that is true for you and you are also using Anaconda on a Mac with El Capitan, try this:

    conda install --channel https://conda.anaconda.org/RMG graphviz`
    conda install --channel https://conda.anaconda.org/RMG pydot
    
    0 讨论(0)
  • 2020-11-28 02:12

    I forked the pydot repository [1], applied the Gabi Davar patch and some changes to support python-3. The package is available in the PyPI [2].

    Cheers

    • [1] https://pypi.python.org/pypi/pydot2/1.0.32
    • [2] https://pypi.python.org/pypi/pydot2
    0 讨论(0)
  • 2020-11-28 02:13

    When other solutions do not work, this is a quick and dirty method to solve the probem:

    This example is from python 2.7 on Ubuntu 16.04.

    Edit the file python2.7/site-packages/keras/utils/visualize_util.py and comment the code segment below.

    if not pydot.find_graphviz():
        raise ImportError('Failed to import pydot. You must install pydot'
                          ' and graphviz for `pydotprint` to work.')
    

    find_graphviz() is redundant on newer versions of pydot, and the above call does not work.

    0 讨论(0)
  • 2020-11-28 02:14

    $ sudo pip uninstall pydot

    $ sudo pip install pydot2

    See the following link: http://infidea.net/troubleshooting-couldnt-import-dot_parser-loading-of-dot-files-will-not-be-possible/

    0 讨论(0)
  • 2020-11-28 02:14

    You need to downgrade pyparsing from version 2.x to version 1.5.7 to get pydot to work correctly.

    For win-64, using Conda, this worked for me:

    conda install -c https://conda.anaconda.org/Trentonoliphant pyparsing=1.5.7
    

    I then disabled/uninstalled the 2.x version and reloaded pyparsing in my script:

    pyparsing = reload(pyparsing)
    pydot = reload(pydot)
    

    To check whether you have the right version running:

    print pyparsing.__version__
    
    0 讨论(0)
提交回复
热议问题