Failed to import pydot 및 graphviz error: (2,'RegOpenKeyEx', 오류 요약

Theano Tutorial에 따라 Theano 그림 구조를 작성하다가 문제가 생겼습니다.예제 코드:
import theano
import theano.tensor as T
from theano import function
import pydot
a = theano.tensor.vector("a")      # declare symbolic variable
b = a + a ** 10                    # build symbolic expression
f = theano.function([a], b)        # compile function
print f([0, 1, 2])                 # prints `array([0,2,1026])`
[    0.,     2.,  1026.]
theano.printing.pydotprint(b, outfile="./pics/symbolic_graph_unopt.png", var_with_name_simple=True)  
theano.printing.pydotprint(f, outfile="./pics/symbolic_graph_opt.png", var_with_name_simple=True)  

error1:

Failed to import pydot

해결 방법: pip로pydot와graphviz를 설치하고 윈도우즈 플랫폼에서 msi파일을 다운로드하여 수동으로 설치해야 합니다.graphviz 다운로드 주소:https://pypi.python.org/pypi/graphviz/0.3.3
pyparsing 재설치:
pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
pip install pydot

pydot과 graphviz가 성공적으로 설치되었는지 테스트합니다.
import pydot
print pydot.find_graphviz()

None으로 돌아가면,pydot에서graphviz를 찾을 수 없음,error2 해결 방법을 보십시오.

error2:

graphviz error: (2, 'RegOpenKeyEx'...

pydot에서graphviz를 찾을 수 없습니다.pydot을 수동으로 수정합니다.find_graphviz () 함수, 예를 들어 나는 이렇게 고쳤다.
def find_graphviz():
    """Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the PATH environment variable. Thirdly: Default install location (Windows only) It will look for 'dot', 'twopi' and 'neato' in the default install location under the "Program Files" directory. It will return a dictionary containing the program names as keys and their paths as values. If this fails, it returns None. """

    # Method 1 (Windows only)
    #
#======================= , if graphviz ================
# if os.sys.platform == 'win32':
# 
# try:
# import win32api, win32con
# 
# # Get the GraphViz install path from the registry
# #
# hkey = win32api.RegOpenKeyEx( win32con.HKEY_LOCAL_MACHINE,
# "SOFTWARE\ATT\Graphviz", 0, win32con.KEY_QUERY_VALUE )
# 
# path = win32api.RegQueryValueEx( hkey, "InstallPath" )[0]
# win32api.RegCloseKey( hkey )
# 
# # Now append the "bin" subdirectory:
# #
# path = os.path.join(path, "bin")
# progs = __find_executables(path)
# if progs is not None :
# #print "Used Windows registry"
# return progs
# 
# except ImportError :
# # Print a messaged suggesting they install these?
# #
# pass
# 
#==============================================================================
    # Method 2 (Linux, Windows etc)
    #
    if os.environ.has_key('PATH'):

        for path in os.environ['PATH'].split(os.pathsep):
            progs = __find_executables(path)
            if progs is not None :
                #print "Used path"
                return progs

    # Method 3 (Windows only)
    #
    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"D:\deeplearning\graphviz\bin"

        progs = __find_executables(path)

        if progs is not None :

            #print "Used default install location"
            return progs

    # ,path graphviz 
    path = r"D:\xxx\graphviz\bin"

    progs = __find_executables(path)

    if progs is not None :

        #print "Used default install location"
        return progs

    for path in (
        '/usr/bin', '/usr/local/bin',
        '/opt/bin', '/sw/bin', '/usr/share',
        '/Applications/Graphviz.app/Contents/MacOS/' ):

        progs = __find_executables(path)
        if progs is not None :
            #print "Used path"
            return progs

    # Failed to find GraphViz
    #
    return None

참고 자료:


GraphViz’s executables not found on Windows 7 64-bit if user installs them in a custom directory #91:https://github.com/erocarrera/pydot/issues/91
pydot and graphviz error: Couldn’t import dot_parser, loading of dot files will not be possible:http://stackoverflow.com/questions/15951748/pydot-and-graphviz-error-couldnt-import-dot-parser-loading-of-dot-files-will
RuntimeError: Failed to import pydot. #1801:https://github.com/Theano/Theano/issues/1801

좋은 웹페이지 즐겨찾기