Emacs下plantuml报错 dot executeable /opt/local/bin/dot

错误

#+BEGIN_SRC plantuml :file temp/a.png :cmdline -charset UTF-8
 @startuml
left to right direction
actor Guest as g
package Professional {
  actor Chef as c
  actor "Food Critic" as fc
}
package Restaurant {
  usecase "Eat Food" as UC1
  usecase "Pay for Food" as UC2
  usecase "Drink" as UC3
  usecase "Review" as UC4
}
fc --> UC4
g --> UC1
g --> UC2
g --> UC3
@enduml
#+END_SRC

在plantuml官网上随便抄了段代码。执行,发现不出图片,

a.png

原因

没有安装graphviz这个库

检查

# mahaiqiang @ mahaiqiangdeAir in ~ [23:33:40]
$ dot -version
zsh: command not found: dot

好吧,确实没有安装,
其实早之前的程序猿的MacOS环境(三)记录过要安装的,但是换了笔记本,没有安装。

安装

# macos
brew install Graphviz

测试

$ dot -version
dot - graphviz version 3.0.0 (20220226.1711)
libdir = "/opt/homebrew/Cellar/graphviz/3.0.0/lib/graphviz"
Activated plugin library: libgvplugin_dot_layout.6.dylib
Using layout: dot:dot_layout
Activated plugin library: libgvplugin_core.6.dylib
Using render: dot:core
Using device: dot:dot:core
The plugin configuration file:
    /opt/homebrew/Cellar/graphviz/3.0.0/lib/graphviz/config6
        was successfully loaded.
    render  :  cairo dot dot_json fig gd json json0 map mp pic pov ps quartz svg tk visio vml vrml xdot xdot_json
    layout  :  circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
    textlayout  :  textlayout
    device  :  bmp canon cgimage cmap cmapx cmapx_np dot dot_json eps exr fig gd gd2 gif gv icns ico imap imap_np ismap jp2 jpe jpeg jpg json json0 mp pct pdf pic pict plain plain-ext png pov ps ps2 psd sgi svg svgz tga tif tiff tk vdx vml vmlz vrml wbmp webp xdot xdot1.2 xdot1.4 xdot_json
    loadimage   :  (lib) bmp eps gd gd2 gif jpe jpeg jpg pdf png ps svg webp xbm

然后把 dot二进制可执行文件 复制到 plantUML查找dot的位置

sudo mkdir -p /opt/local/bin
sudo cp /opt/homebrew/Cellar/graphviz/2.49.3/bin/dot /opt/local/bin

测试

工具使用
直接使用plantUML
先编辑一个uml代码文档(test.txt),如下是test.txt的内容

@startuml
Alice -> Bob: test
@enduml

调用plantUML生成uml图(图片格式)注:在当前目录下会生成test.png图片

java -jar plantuml.jar test.txt

emacs里

#+begin_src plantuml :cmdline -charset utf-8 :file temp/test.png
@startuml
left to right direction
actor Guest as g
package Professional {
  actor Chef as c
  actor "Food Critic" as fc
}
package Restaurant {
  usecase "Eat Food" as UC1
  usecase "Pay for Food" as UC2
  usecase "Drink" as UC3
  usecase "Review" as UC4
}
fc --> UC4
g --> UC1
g --> UC2
g --> UC3
@enduml
#+end_src
image.png

注意

在使用plantUml前,一定要先下载 plantUML.jar.
我本地是直接将jar放在.emacs.d跟目录下。
然后再配置文件里指定了jar包路径

;;;设置jar包路径
(setq org-plantuml-jar-path
      (expand-file-name "~/.emacs.d/jar/plantuml.1.2021.9.jar"))
(setq org-ditaa-jar-path
      (expand-file-name "~/.emacs.d/jar/ditaa0_9.jar"))

这样就可以离线使用。

你可能感兴趣的:(Emacs下plantuml报错 dot executeable /opt/local/bin/dot)