目录
我在使用graphviz这个第三方库,python实现求两点间所有路径的算法 并使用 graphviz 图形化展示路径。
graphviz.backend.execute.ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz executables are on your systems' PATH

大家习惯pip install graphviz去安装,但是graphviz是个软件,不能单独用Pip安装。
(1)先将自己安装好的卸载
pip uninstall graphviz

(2)首先要重新安装这个第三方库,
pip install graphviz

(3)然后下载graphviz的安装包 ,网址:
https://graphviz.org/download/
进入下面页面。此处我选择这个版本进行下载,


(4)下载之后,点击下载成功的.exe文件(本文简称graphziv.exe)进行安装,一路默认即可,安装的时候记住安装路径(最好放到anaconda文件夹下,即**\Anaconda\Graphziv后续配置环境变量的时候要使用) ,

在安装过程中,一定要注意:将之加入到环境变量中去
(5)如果没有加入请参考此步骤进行添加环境变量,
1.此电脑右键----->属性----->高级系统设置----->环境变量----->xxx的用户变量u----->path----->新建
粘贴文件的安装路径+\bin :例如D:\python\graphviz\bin


2. 此电脑右键----->属性----->高级系统设置----->环境变量----->系统环境变量(s)----->path----->新建
粘贴文件的安装路径+\bin\dot.exe :例如D:\python\graphviz\bin\dot.exe


(6)运行我的py代码,

其中,
graph.txt:
代码应能读取规定格式的
TXT文档作为输入,格式如下:
第一行:图的节点数N,边数V
后续V行: 图中每一条边的起点、终点
最后一行:待求解目标的起点、终点
16 20
1 2
1 5
2 3
2 4
3 4
3 5
4 5
5 7
5 14
5 6
6 9
7 4
9 4
10 6
11 5
12 7
13 8
13 6
15 13
16 10
2 5
#!/usr/bin/env python3
#find_all_routes_of_2_points.py
#fumiama 20201001
import sys
from graphviz import Digraph
def exitWithError(*error):
print(*error)
exit()
def printGraph2Pdf(grf): grf.render('graph-output/output.gv', view=True)
def printRoute(stackList):
global nodeNumber
nodeNumber += 1
dot.node(str(nodeNumber), stackList[0])
for node in stackList[1:]:
nodeNumber += 1
dot.node(str(nodeNumber), node)
dot.edge(str(nodeNumber-1), str(nodeNumber))
def addEdge(a, b):
global edgeLinks
if a not in edgeLinks: edgeLinks[a] = set()
if b not in edgeLinks: edgeLinks[b] = set()
edgeLinks[a].add(b)
edgeLinks[b].add(a)
def loadGraph(fileName):
try: f = open(fileName, 'r')
except: exitWithError("打开文件失败, 请检查文件名是否正确或程序是否有权限访问")
global size, edgeLinks
size, edgeCount = map(int, f.readline().split())
print("节点:", size, "边数:", edgeCount)
for i in range(1, size+1): dot.node(str(i), str(i))
for i in range(edgeCount):
a, b = f.readline().split()
addEdge(a, b)
dot.edge(a, b)
re = f.readline()
f.close()
return re
def findAllRoutes(start, end):
global edgeLinks, stack
stack.append(start)
if start == end:
print("找到路径:", stack)
printRoute(stack)
stack.pop()
else:
for nextPoint in edgeLinks[start]:
if nextPoint not in stack: findAllRoutes(nextPoint, end)
stack.pop()
def rmRoute2Itself(start):
for point in edgeLinks:
if point != start and start in edgeLinks[point]:
edgeLinks[point].remove(start)
if __name__ == '__main__':
dot = Digraph(comment='Gragh2Print')
dot.edge_attr.update(arrowhead='none')
dot.graph_attr['rankdir'] = 'LR'
edgeLinks = dict()
size = 0
stack = []
nodeNumber = 0
# sys = "D:find_all_routes_of_2_points.py pdf graph.txt"
# if len(sys.argv) != 3: exitWithError("用法:", sys.argv[0], "[pdf|nopdf] 文件位置")
a, b = loadGraph("graph.txt").split()
print("起点:", a, "终点:", b)
rmRoute2Itself(a)
nodeNumber = size + 1
findAllRoutes(a, b)
print("生成pdf格式图形化报告...")
printGraph2Pdf(dot)
就可以看到最后生成的结果了,
节点: 16 边数: 20
起点: 2 终点: 5
找到路径: ['2', '3', '5']
找到路径: ['2', '3', '4', '5']
找到路径: ['2', '3', '4', '7', '5']
找到路径: ['2', '3', '4', '9', '6', '5']
找到路径: ['2', '4', '5']
找到路径: ['2', '4', '7', '5']
找到路径: ['2', '4', '9', '6', '5']
找到路径: ['2', '4', '3', '5']
找到路径: ['2', '1', '5']
生成pdf格式图形化报告...
并且生成pdf文件,

打开pdf文件显示为:

ok,问题解决。
我正在尝试在我的远程服务器上运行以下命令(通过capistrano或ssh):bundleexecRAILS_ENV=productionscript/delayed_jobstart但我收到此错误消息:bundler:notexecutable:script/delayed_job以前从未见过这个,谷歌也没有适合我的东西。知道可能是什么问题吗? 最佳答案 也许它没有运行权限?尝试运行这个命令chmod+xscript/delayed_job然后再次执行文件。 关于ruby-on-rai
尝试构建SASS时,我在SublimeText2上遇到以下错误。我从这里添加了SASS构建插件https://github.com/jaumefontal/SASS-Build-SublimeText2env:ruby_executable_hooks:没有那个文件或目录[在0.0秒内完成,退出代码为127]不太确定我应该在这里做什么来解决这个问题。谢谢!!反对票的数量告诉我需要添加更多信息。问题是我不太确定应该添加哪些信息。我的SASS.sublime-build文件位于/Library/ApplicationSupport/SublimeText2/Packages/SASSB
亲测可用。Anerroroccurredwhileresolvingpackages:Projecthasinvaliddependencies: com.unity.xxx:No'git'executablewasfound.PleaseinstallGitonyour systemthenrestartUnityandUnityHub在我们使用PackageManager时,Unity允许我们使用Git上的package(点击加号,选择addpackagefromgitURL,或者是直接在Asset/Packages/manifest.json中添加包名)。但是这种操作需要我们事先装好g
我需要在Rails4中允许一个名称中有一个点的参数:我的params散列如下所示:{"dictionary_objects.id"=>["102","110","106"]}我可以获得参数值:>>params['dictionary_objects.id']=>[[0]"102",[1]"110",[2]"106"]但是当我尝试允许它时,它返回一个空散列:>>params.permit('dictionary_objects.id')Unpermittedparameters:dictionary_objects.id=>{}有人知道我怎样才能允许名称中带有点的参数吗?谢谢。
我想安装herokutoolbelt。我选择完全安装。安装时出现此错误。安装完成后herokulogin不起作用。 最佳答案 试试这个:Followthislink无论它是否与在Windows7上运行游戏有关,请在您的Windows8上尝试这个。如果它有效,请告诉我们。 关于ruby-在Windows8:UnabletoexecutefileC:\ProgramFiles(x86)\Heroku\ruby-1.9.3\bin\gem.bat上安装herokutoolbelt时出错,我们在
VIM中是否有可能为ruby代码重复“执行和更新‘#=>’标记”TextMate功能。我想要这样的东西:x=2classAdefa42endendx#=>A.new.a#=>输入一些命令...然后得到x=2classAdefa42endendx#=>2A.new.a#=>42这是来自CiaránWalsh’sBlog的对此功能的描述:Anothertooldefinitelyworthknowingisthe"ExecuteandUpdate'#=>'Markers"command(on⌃⇧⌘Ebydefault).Touseit,addsomecommentmarkers(the
在使用ActiveRecord::BaseConnection类执行SQL语句后,如何找到PostgreSQL处理的记录数?temp_sql="UPDATEtable_aSETcolumn_a='abc'WHEREcolumn_b=1"result=ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)或者您可以建议更好的方法来做到这一点。请记住,上面的更新声明是一个简单的更新声明,以保持问题简短。我真正的查询是“基于集合”的,涉及复杂的创建临时表、更新、插入语句。
当我运行rakedb:migrate时出现这个错误rakeaborted!Savingdiagramfailed!VerifythatGraphvizisinstalledandinyourpath,orusefiletype=dot.完整日志:rakedb:migrateLoadingapplicationenvironment...LoadingcodeinsearchofActiveRecordmodels...GeneratingEntity-RelationshipDiagramfor20models...rakeaborted!Savingdiagramfailed!Ver
我正在尝试测试我的应用程序正在使用的引擎内部的Controller。规范不在引擎中,而是在应用程序本身中(我试图在引擎中进行测试,但也遇到了问题)。我的引擎有以下routes.rb:Revision::Engine.routes.drawdoresources:steps,only:[]docollection{get:first}endend引擎正常挂载在应用routes.rb上:mountRevision::Engine=>"revision"当我运行rakeroutes时,在最后一行我得到:RoutesforRevision::Engine:first_stepsGET/step
我正在使用原始/裸机sql插入来提高我服务的写入性能。我的模块中有这样的东西-insert="('#{id}','#{status}','#{some_time_val}')"sql_string="INSERTINTOhistory('device_id','status','time')VALUES#{insert}"ActiveRecord::Base.connection.executesql_string当我编写如下所示的rspec时,它会测试除插入是否通过之外的所有内容。因此,由于rspec、database_cleaner等执行回滚和事务的方式,我的期望永远不会奏效。我尝