Inkscape Mac 命令行使用
Inkscape是用于编辑SVG格式文件的软件,论文作图需要,但是Mac安装后无法使用命令行,查询了发现相关资料较少,故记录一下。
-
下载dmg文件安装
安装链接 https://inkscape.org/release/inkscape-master/?latest=1 -
添加环境变量
要使用命令行需要将路径添加到path
可执行文件路径 :
老版本:/Applications/Inkscape.app/Contents/Resources/bin/inkscape
新版本:/Applications/Inkscape.app/Contents/MacOS/inkscape
终端输入:
vi ~/.bashrc
# 添加环境变量
alias inkscape="/Applications/Inkscape.app/Contents/MacOS/inkscape"
# source 生效
source ~/.bashrc
- 使用
inkscape --help
显示如下,即可使用命令行操作:
转化文件格式
inkscape -z target.svg -M target.emf
- Python程序自动转化svg到emf
这里需要注意的是,即使设置了环境变量,在python subprocess 使用的shell中依然可能没有这个环境变量,因此cmd中还是需要使用inkscape的完整路径。
import numpy as np
import matplotlib.pyplot as plt
import subprocess
def convertSVGtoEMF(figname):
cmd = '/Applications/Inkscape.app/Contents/MacOS/inkscape -p %s.svg -o %s.emf' % (figname, figname)
print('running ... ' + cmd)
result = [] # 储存cmd中结果
process = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderrinfo, stdoutinfo = process.communicate()
print(stdoutinfo)