0

I am attempting to simply export an IPython notebook to a PDF. I cannot get past a syntax error that makes no sense to me.

ipython nbconvert "TestBook.ipynb" --to=latex --post=PDF
File "<ipython-input-45-98f03ab096ad>", line 1
ipython nbconvert "TestBook.ipynb" --to=latex --post=PDF
                ^
SyntaxError: invalid syntax

I'm new to python and IPython, but I'm at a complete loss here. Any ideas?

Tyler
  • 3
  • 1
  • 2

2 Answers2

2

Looks like you are trying to run this in the python shell

>>> ipython nbconvert "TestBook.ipynb" --to=latex --post=PDF
  File "<stdin>", line 1
    ipython nbconvert "TestBook.ipynb" --to=latex --post=PDF
                    ^
SyntaxError: invalid syntax
>>> 

Exit from the shell, and run it from the command line instead.

karthikr
  • 97,368
  • 26
  • 197
  • 188
0

As @karthikr said, you are trying to run the code in the python shell. If you want to run the command from a python shell you could use subprocess module.

To run your command in windows powershell:

import subprocess
cmd = 'ipython nbconvert TestBook.ipynb --to=latex --post=PDF'
subprocess.run(['powershell', '-Command', cmd])

To run your command on the bash:

import subprocess
cmd = 'ipython nbconvert TestBook.ipynb --to=latex --post=PDF'
subprocess.run(['/bin/bash', '-c', cmd])

If you are on Jupiter notebook you could easily use this line:

!ipython nbconvert TestBook.ipynb --to=latex --post=PDF