program story

pydot 및 graphviz 오류 : dot_parser를 가져올 수 없습니다. 도트 파일을로드 할 수 없습니다

inputbox 2020. 8. 6. 08:18
반응형

pydot 및 graphviz 오류 : dot_parser를 가져올 수 없습니다. 도트 파일을로드 할 수 없습니다


pydot로 매우 간단한 코드를 실행할 때

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

for i in range(3):

  edge = pydot.Edge("king", "lord%d" % i)
  graph.add_edge(edge)

vassal_num = 0
for i in range(3):
  for j in range(2):
    edge = pydot.Edge("lord%d" % i, "vassal%d" % vassal_num)
    graph.add_edge(edge)
    vassal_num += 1

graph.write_png('example1_graph.png')

오류 메시지가 표시됩니다.

Couldn't import dot_parser, loading of dot files will not be possible.

파이썬 2.7.3을 사용하고 있습니다


에 대한 답변 pydot >= 1.1:

(상류)의 비 호환성 pydot에 의해 고정되어 6dff94b3f1 , 따라서 pydot >= 1.1것이다 호환pyparsing >= 1.5.7 .


답변 pydot <= 1.0.28:

이 문제를 겪는 다른 사람에게는 pyparsing이 1.x에서 2.x 릴리스로 변경 되었기 때문입니다. pip를 사용하여 pydot를 설치하려면 먼저 이전 버전의 pyparsing을 설치하십시오.

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

pyparsing사용하여 설치하지 않고 pip대신 사용 setup.py하는 경우이 솔루션보고 패키지를 제거하십시오. @qtips 감사합니다.


pyparsing2와 함께 올바르게 작동하는 pydot2라는 pip repo에 새로운 패키지가 있습니다. matplotlib가 최신 pyparsing 패키지에 의존하기 때문에 패키지를 다운 그레이드 할 수 없습니다.

참고 : macports의 python2.7


pydot는 pyparsing의 개인 모듈 변수 (_noncomma)를 사용했습니다. 아래 diff는 pyparsing 2.0.1에 사용하도록 수정했습니다.

diff --git a/dot_parser.py b/dot_parser.py
index dedd61a..138d152 100644
--- a/dot_parser.py
+++ b/dot_parser.py
@@ -25,8 +25,9 @@ from pyparsing import __version__ as pyparsing_version
 from pyparsing import ( nestedExpr, Literal, CaselessLiteral, Word, Upcase, OneOrMore, ZeroOrMore,
     Forward, NotAny, delimitedList, oneOf, Group, Optional, Combine, alphas, nums,
     restOfLine, cStyleComment, nums, alphanums, printables, empty, quotedString,
-    ParseException, ParseResults, CharsNotIn, _noncomma, dblQuotedString, QuotedString, ParserElement )
+    ParseException, ParseResults, CharsNotIn, dblQuotedString, QuotedString, ParserElement )

+_noncomma = "".join( [ c for c in printables if c != "," ] )

 class P_AttrList:

나는 pydot 저장소를 포크하고 [1] Gabi Davar 패치와 python-3을 지원하기 위해 몇 가지 변경 사항을 적용했습니다. 패키지는 PyPI [2]에서 사용할 수 있습니다.

건배


$ sudo pip uninstall pydot

$ sudo pip install pydot2

다음 링크를 참조하십시오 : http://infidea.net/troubleshooting-couldnt-import-dot_parser-loading-of-dot-files-will-not-be-possible/


The solution was not to install pydot from somewhere, but "python-pydot" from official ubuntu repositories.


There are now at least 2 more versions that appear to support PyParsing-2 and Python-3:


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

This worked for me (Mac OS X 10.9 with Python 2.7.10 on Anaconda):

conda uninstall pydot

Then,

conda install pydot

Pyparsing is then downgraded (from 2.x to 1.5.7) upon pydot's installation. Future Googlers: this allowed me to install and import Theano correctly.


What I did at the end after so many tries from what i saw here (pseudo sequence for it to work for networkx ) :

apt-get remove python-pydot
pip install pydotplus
apt-get install libcgraph6
apt-get install python-pygraphviz


# pip freeze | grep pydot
 pydotplus==2.0.2
# pip freeze | grep pyparsing
pyparsing==2.2.0
# pip freeze | grep graphviz
pygraphviz==1.2
# python -c 'import pydotplus'
#

On OSX Mavericks the following did the trick... I got the same error but at the bottom there was also a complaint that the graphviz executable was not present... I think the problem was i had installed graphviz prior to the other modules?

brew uninstall graphviz
brew install graphviz

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.


I also met the problem and my pydot==1.0.28 while pyparsing==2.2.0. I fixed the problem by downloading the newest pydot 1.2.3(tar.gz)from google and then install it offline. When I updated the pydot in ubuntu 14.04, it said the pydot 1.0.28 is the newest version. Therefore I download from the google the 1.2.3 version.


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__

참고URL : https://stackoverflow.com/questions/15951748/pydot-and-graphviz-error-couldnt-import-dot-parser-loading-of-dot-files-will

반응형