如何解决jupyter nbconvert to PDF 引发 PermissionError: [WinError 5]
我正在尝试将 Jupyter 笔记本转换为 PDF 文件,但一直收到以下错误:
[NbConvertApp] Converting notebook ejercicios.ipynb to pdf
Traceback (most recent call last):
...
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\exporters\exporter.py",line 143,in from_notebook_node
nb_copy,resources = self._preprocess(nb_copy,resources)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\exporters\exporter.py",line 318,in _preprocess
nbc,resc = preprocessor(nbc,resc)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\base.py",line 47,in __call__
return self.preprocess(nb,resources)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\base.py",line 69,in preprocess
nb.cells[index],resources = self.preprocess_cell(cell,resources,index)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\convertfigures.py",line 45,in preprocess_cell
output.data[self.to_format] = self.convert_figure(
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\svg2pdf.py",line 125,in convert_figure
shell = self.command.format(from_filename=input_filename,File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py",line 575,in __get__
return self.get(obj,cls)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py",line 538,in get
default = obj.trait_defaults(self.name)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py",line 1578,in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py",line 975,in __call__
return self.func(*args,**kwargs)
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\nbconvert\preprocessors\svg2pdf.py",line 77,in _command_default
major_verison = self.inkscape_version.split('.')[0]
File "c:\users\netoo\appdata\local\programs\python\python38\lib\site-packages\traitlets\traitlets.py",line 57,in _inkscape_version_default
p = subprocess.Popen([self.inkscape,'--version'],File "c:\users\netoo\appdata\local\programs\python\python38\lib\subprocess.py",line 858,in __init__
self._execute_child(args,executable,preexec_fn,close_fds,line 1311,in _execute_child
hp,ht,pid,tid = _winapi.CreateProcess(executable,args,PermissionError: [WinError 5] Acceso denegado
看起来该命令的默认权限不足以创建 Inkscape 进程,但我已经在使用具有管理员权限的命令行。
去年我能够成功地将笔记本转换为 PDF,它是同一台机器,但我使用的是另一个版本的 Python,3.6 或 3.7,这与此有关吗?
解决方法
我在这里报告了这个问题https://github.com/jupyter/nbconvert/issues/1525
我的临时解决方案是使用绝对路径作为我安装 Inkscape 的字符串文字,而不是调用 self.inkscape
,在我的情况下,路径是 'C:\\Program Files\\Inkscape\\inkscape.exe'
:
https://github.com/jupyter/nbconvert/blob/88baf7a9ca724d74c9f890a60d5c3680e8959a14/nbconvert/preprocessors/svg2pdf.py#L57
在那一行我有p = subprocess.Popen(['C:\\Program Files\\Inkscape\\inkscape.exe','--version']
。
我打印了 self.inkscape
,输出是 'C:\Program Files\Inkscape\inkscape.exe'
。我认为这是因为双反斜杠,所以我尝试了 os.path.abspath(self.inkscape)
但它添加了我在开头调用命令的位置的当前路径。我也试过 pathlib.Path(self.inkscape)
但它没有用,所以我不知道可能是什么问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。