theano 0.8与pydot、graphziv的冲突解决
2016-02-29 12:00
549 查看
在python中import theano时,如果出现Couldn't import dot_parser, loading of dot files will not be possible.之类的错误,可以按如下步骤解决
1. pip uninstall pydot pyparsing graphviz
2.如果是window,先安装graphviz-2.38.msi;如果是Ubuntu系统,则apt-get install graphviz,并将graphviz的bin目录的路径添加到系统PATH变量中
3.pip install graphviz
4.pip install pyparsing==2.0.1
4.pip install pydot
经此几个步骤后,应该就可以正常使用theano和pydot等库文件了。如果还是无法正确找到graphviz的可执行文件,则采用第二种方法:
在Python的安装目录中找到Lib\site-packages\pydot.py文件,手动修改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...,修改此次,将<span style="line-height: 26px; font-family: 'microsoft yahei';">path直接指向graphviz安装路径</span>
<span style="color:#ff0000;">path = r"C:\Program Files (x86)\Graphviz2.38\bin"</span>
progs = __find_executables(path)
if progs is not None :
#print "Used default install location"
return progs
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
1. pip uninstall pydot pyparsing graphviz
2.如果是window,先安装graphviz-2.38.msi;如果是Ubuntu系统,则apt-get install graphviz,并将graphviz的bin目录的路径添加到系统PATH变量中
3.pip install graphviz
4.pip install pyparsing==2.0.1
4.pip install pydot
经此几个步骤后,应该就可以正常使用theano和pydot等库文件了。如果还是无法正确找到graphviz的可执行文件,则采用第二种方法:
在Python的安装目录中找到Lib\site-packages\pydot.py文件,手动修改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...,修改此次,将<span style="line-height: 26px; font-family: 'microsoft yahei';">path直接指向graphviz安装路径</span>
<span style="color:#ff0000;">path = r"C:\Program Files (x86)\Graphviz2.38\bin"</span>
progs = __find_executables(path)
if progs is not None :
#print "Used default install location"
return progs
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
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法