Open magerton opened 3 years ago
Here are the explicit python environments
That's probably unrelated to Julia, looks like the Inkscape path that was found is pointing to an executable that needs admin privilages to use. 6.0 has a different code path for finding inkscape that can search your registry instead of looking in fixed paths. I can't reproduce this easily on my machine, so you likely need to modify nbconvert to print what the self.inkscape
value is in svg2pdf.py
and tracing that path to figure out why permissions are such on that executable.
I'm not very good with python, and so not sure exactly how to have things print (adding a simple print statement didn't do the trick.... but I may have been modifying the wrong file). However, the registry value script gets to is just the executable: "C:\Program Files\Inkscape\inkscape.exe"
. FWIW, installing requires admin permissions (and my account isn't an admin account).
Can you try running the nbconvert call as an admin? It sounds like it simply can't call "C:\Program Files\Inkscape\inkscape.exe"
. If that's the case maybe look into opening up permissions for that executable to be used by your account.
Just ran the script as admin, and I get the same error.
(base) PS E:\projects\are254-fall2020\assignments> jupyter nbconvert --debug --to=pdf .\python-mwe-no-issues.ipynb.txt
[NbConvertApp] Searching ['E:\\projects\\are254-fall2020\\assignments', 'C:\\Users\\mjaadmin\\.jupyter', 'D:\\libraries\\julia\\conda\\3\\etc\\jupyter', 'C:\\ProgramData\\jupyter'] for config files
[NbConvertApp] Looking for jupyter_config in C:\ProgramData\jupyter
[NbConvertApp] Looking for jupyter_config in D:\libraries\julia\conda\3\etc\jupyter
[NbConvertApp] Looking for jupyter_config in C:\Users\mjaadmin\.jupyter
[NbConvertApp] Looking for jupyter_config in E:\projects\are254-fall2020\assignments
[NbConvertApp] Looking for jupyter_nbconvert_config in C:\ProgramData\jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in D:\libraries\julia\conda\3\etc\jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in C:\Users\mjaadmin\.jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in E:\projects\are254-fall2020\assignments
[NbConvertApp] Converting notebook .\python-mwe-no-issues.ipynb.txt to pdf
[NbConvertApp] Notebook name is 'python-mwe-no-issues.ipynb'
[NbConvertApp] Template paths:
C:\Users\mjaadmin\AppData\Roaming\jupyter\nbconvert\templates\latex
D:\libraries\julia\conda\3\share\jupyter\nbconvert\templates\latex
C:\ProgramData\jupyter\nbconvert\templates\latex
C:\Users\mjaadmin\AppData\Roaming\jupyter\nbconvert\templates\latex
D:\libraries\julia\conda\3\share\jupyter\nbconvert\templates\latex
C:\ProgramData\jupyter\nbconvert\templates\latex
D:\libraries\julia\conda\3\share\jupyter\nbconvert\templates\base
C:\Users\mjaadmin\AppData\Roaming\jupyter
C:\Users\mjaadmin\AppData\Roaming\jupyter\nbconvert\templates
C:\Users\mjaadmin\AppData\Roaming\jupyter\nbconvert\templates\compatibility
D:\libraries\julia\conda\3\share\jupyter
D:\libraries\julia\conda\3\share\jupyter\nbconvert\templates
D:\libraries\julia\conda\3\share\jupyter\nbconvert\templates\compatibility
C:\ProgramData\jupyter
C:\ProgramData\jupyter\nbconvert\templates
C:\ProgramData\jupyter\nbconvert\templates\compatibility
[NbConvertApp] Applying preprocessor: TagRemovePreprocessor
[NbConvertApp] Applying preprocessor: RegexRemovePreprocessor
[NbConvertApp] Applying preprocessor: coalesce_streams
[NbConvertApp] Applying preprocessor: SVG2PDFPreprocessor
Traceback (most recent call last):
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 535, in get
value = obj._trait_values[self.name]
KeyError: 'command'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 535, in get
value = obj._trait_values[self.name]
KeyError: 'inkscape_version'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\libraries\julia\conda\3\Scripts\jupyter-nbconvert-script.py", line 10, in <module>
sys.exit(main())
File "D:\libraries\julia\conda\3\lib\site-packages\jupyter_core\application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\config\application.py", line 837, in launch_instance
app.start()
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\nbconvertapp.py", line 350, in start
self.convert_notebooks()
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\nbconvertapp.py", line 524, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\nbconvertapp.py", line 489, in convert_single_notebook
output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\nbconvertapp.py", line 418, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\exporter.py", line 181, in from_filename
return self.from_file(f, resources=resources, **kw)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\exporter.py", line 199, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\pdf.py", line 168, in from_notebook_node
latex, resources = super().from_notebook_node(
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\latex.py", line 77, in from_notebook_node
return super().from_notebook_node(nb, resources, **kw)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\templateexporter.py", line 369, in from_notebook_node
nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\exporter.py", line 143, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\exporters\exporter.py", line 318, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
return self.preprocess(nb, resources)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\base.py", line 69, in preprocess
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\convertfigures.py", line 45, in preprocess_cell
output.data[self.to_format] = self.convert_figure(
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 125, in convert_figure
shell = self.command.format(from_filename=input_filename,
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
return self.get(obj, cls)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 538, in get
default = obj.trait_defaults(self.name)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 1577, in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
return self.func(*args, **kwargs)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 77, in _command_default
major_verison = self.inkscape_version.split('.')[0]
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
return self.get(obj, cls)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 538, in get
default = obj.trait_defaults(self.name)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 1577, in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
return self.func(*args, **kwargs)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 57, in _inkscape_version_default
p = subprocess.Popen([self.inkscape, '--version'],
File "D:\libraries\julia\conda\3\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\libraries\julia\conda\3\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
@MSeal, here's an even smaller MWE that works when run from a simple python terminal. It looks like things blow up when the inkscape version gets requested from the shell. I've tried tinkering w/ the code in the Conda package to see if I could further diagnose, but I'm actually not sure that I'm editing the right file and getting python to see it... I wish I could be of more help!
I'll note that getting the Inkscape version from the command line requires that I execute the .com
file, not the .exe
. See output from Cmd.exe below.
C:\Users\magerton>"C:\Program Files\Inkscape\inkscape.com" --version
Inkscape 0.92.4 (5da689c313, 2019-01-14)
C:\Users\magerton>"C:\Program Files\Inkscape\inkscape.exe" --version
C:\Users\magerton>
from nbconvert import preprocessors
x = preprocessors.SVG2PDFPreprocessor()
# adobe SVG
SVG_STR = "<svg viewBox='0 0 105 93' xmlns='http://www.w3.org/2000/svg'>\n<path d='M66,0h39v93zM38,0h-38v93zM52,35l25,58h-16l-8-18h-18z' fill='#ED1C24'/>\n</svg>\n"
x.inkscape
x.inkscape_version() # fails here
# not run
# x.convert_figure('svg', SVG_STR)
>>> from nbconvert import preprocessors
>>>
>>> x = preprocessors.SVG2PDFPreprocessor()
>>>
>>> # adobe SVG
>>> SVG_STR = "<svg viewBox='0 0 105 93' xmlns='http://www.w3.org/2000/svg'>\n<path d='M66,0h39v93zM38,0h-38v93zM52,35l25,58h-16l-8-18h-18z' fill='#ED1C24'/>\n</svg>\n"
>>>
>>> x.inkscape
'"C:\\Program Files\\Inkscape\\inkscape.exe"'
>>>
>>> x.inkscape_version() # fails here
Traceback (most recent call last):
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 535, in get
value = obj._trait_values[self.name]
KeyError: 'inkscape_version'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 575, in __get__
return self.get(obj, cls)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 538, in get
default = obj.trait_defaults(self.name)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 1577, in trait_defaults
return self._get_trait_default_generator(names[0])(self)
File "D:\libraries\julia\conda\3\lib\site-packages\traitlets\traitlets.py", line 975, in __call__
return self.func(*args, **kwargs)
File "D:\libraries\julia\conda\3\lib\site-packages\nbconvert\preprocessors\svg2pdf.py", line 57, in _inkscape_version_default
p = subprocess.Popen([self.inkscape, '--version'],
File "D:\libraries\julia\conda\3\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\libraries\julia\conda\3\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
I had a similar issue while trying to convert a notebook to PDF via LaTeX in CoCalc.
Error: [NbConvertApp] Converting notebook file-1.ipynb to pdf
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/traitlets/traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'command'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/traitlets/traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'inkscape_version'
During handling of the above exception, another exception occurred:
[...]
RuntimeError: Unable to find inkscape executable --version
When I try to run ìnkscape --version, I obtain the following error
(inkscape:925):Gtk-WARNING **: 13:44:30.837: cannot open display: :0
.
To display the version of inkscape in a terminal, one needs to add the -z
argument, i.e.
~/$ inkscape -z -V
Inkscape 0.92.5 (2060ec1f9f, 2020-04-08)
So maybe adding -z
in this line https://github.com/jupyter/nbconvert/blob/f66ec517275f7c61bb5a36a5d3496ba73005d659/nbconvert/preprocessors/svg2pdf.py#L57 will fix the issues, regarding the errors above.
CC @haraldschilly
This solves it, although os.popen()
uses subprocess.Popen()
, so it's clearly a kludge. Digging into the code for os.popen would probably reveal a cleaner fix. But this works.
Beginning here: https://github.com/jupyter/nbconvert/blob/f66ec517275f7c61bb5a36a5d3496ba73005d659/nbconvert/preprocessors/svg2pdf.py#L57 Make the following change.
try:
p = subprocess.Popen([self.inkscape, '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, _ = p.communicate()
if p.returncode != 0:
raise RuntimeError("Unable to find inkscape executable --version")
except PermissionError:
with os.popen(self.inkscape + ' --version') as p:
output = p.read().encode()
Actually, I returned to this and looked inside os.py. Nothing special about the way subprocess.Popen
is called there.
Changing line 57 to:
p = subprocess.Popen(self.inkscape + ' --version',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, _ = p.communicate()
fixes it. Does this break it on other platforms? If so, could do:
cmd = [inkscape,'--version']
if sys.platform == 'win32':
cmd = ' '.join(cmd) #fix bug on win32
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, _ = p.communicate()
Sorry I've been away for a while -- Popen should be doing the ' '.join
(see Popen docs) but I'm ok with forcing the issue and implementing the windows specific solution as last proposed here. Doing this for all systems can raise issues, so let's only do it for win32
Great! It seems that the function subprocess.list2cmdline
in the subprocess module does something more complicated than join
and doesn't handle the windows path correctly.
Thank you and happy new year!
@MSeal Does this also solves my issues mentioned above? Which happened in a Linux environment and not in Windows.
@MSeal, it turns out that the reason it's failing on windows is semi-intentional: See second comment in https://bugs.python.org/issue37659
@daholzfeind, did you try the fix in your local copy of the code and run it? It looks like a potentially different issue.
@lunarspectrum I worked on this issue 2 months ago, so i cannot test it right now. But what i did, according to git, to fix the gtk error is the following:
$ git diff
diff --git a/nbconvert/preprocessors/svg2pdf.py b/nbconvert/preprocessors/svg2pdf.py
index 9ccaee1c..ee27e926 100644
--- a/nbconvert/preprocessors/svg2pdf.py
+++ b/nbconvert/preprocessors/svg2pdf.py
@@ -54,7 +54,7 @@ class SVG2PDFPreprocessor(ConvertFiguresPreprocessor):
@default('inkscape_version')
def _inkscape_version_default(self):
- p = subprocess.Popen([self.inkscape, '--version'],
+ p = subprocess.Popen([self.inkscape, '-z --version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, _ = p.communicate()
But this only works for inkscape versions < 1.x.x. Above 1.x.x the passed argument raises a deprecation warning --without-gui= is deprecated
.
So to fix my issue we could do a try, except. one with the -z
argument for old inkscape versions and one without -z
.
On my local machine i installed the latest inkscape version for testing reasons. Heres the output:
$ inkscape -z --version
Warning: Option --without-gui= is deprecated
Inkscape 1.1-dev (1:1.0+devel+202101062226+8077427f6d)
Pango version: 1.44.7
In CoCalc the inkscape version depends on your ubuntu base image. I think i have the 20.04 there. This is the output in the "virtual" Terminal:
~$ inkscape -z --version
Inkscape 0.92.5 (2060ec1f9f, 2020-04-08)
~$ inkscape --version
(inkscape:747): Gtk-WARNING **: 08:38:02.726: cannot open display: :0
~$
@MSeal Are there any news for this issue. I still encouter it with version 7.2.5 of nbconvert and version 0.92.5 of Inkscape.
I also see a lot of similar issues corresponding to this problem:
Some issues are closed, stated they solve the issue, but thats not the case if you use an Inkscape version < 1.0.0.
After upgrading nbconvert from 5.6.1 to 6.0.7, I'm unable to convert a jupyter notebook to pdf when the notebook creates a plot using Julia's GR.jl. This seems like it's an issue w/ the conversion via Inkscape. My inkscape version is 0.92.4. Using the Julia Plots.jl pyplot (matplotlib) backend doesn't seem to create this issue. I also don't have this issue if I create a python notebook and use matplotlib to generate a pdf plot.
I don't believe that this is #1325 since my Inkscape directory does have spaces in it
Reproducing issue in python with matplotlib & svg output: python-mwe-no-issues.ipynb.txt
Reproducing issue in Julia:
] add IJulia Plots GR
nbconvert --to=pdf Untitled.ipynb
mwe.ipynb.txt
Nbconvert version: 6.0.7
Conda environment that fails
Conda environment that works
Julia version info