-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion to pdf fails with SVG plots in 6.0.7 (5.6.1 is ok) #1447
Comments
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 |
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: |
Can you try running the nbconvert call as an admin? It sounds like it simply can't call |
Just ran the script as admin, and I get the same error.
|
@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 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)
|
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 To display the version of inkscape in a terminal, one needs to add the
So maybe adding
|
This solves it, although Beginning here:
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 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 |
Great! It seems that the function 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: @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 So to fix my issue we could do a try, except. one with the On my local machine i installed the latest inkscape version for testing reasons. Heres the output:
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:
|
@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
The text was updated successfully, but these errors were encountered: