[Tex/LaTex] Pythontex don’t work ? why

pythontex

I'm working with Windows 8, TeX Live 2015, and Python 3.4. I'm a newbie in LaTeX!

The installation of pythontex seems to be ok. I verify if all the files are at the right place. I try to make pythontex work with this code:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}  
\usepackage{pythontex}
\begin{document}
\begin{pycode} 
 print ("Hello \Latex ")
\end{pycode}
\end{document} 

When I run in cmd:

  • pdflatex test.tex → ok
  • pythontex.py test.py → the file command doesn't exit

Do you have any idea of what's wrong?

Best Answer

In addition to needing to correct the \LaTeX issue, you have a space before the print command. Python will treat this as an improper indentation. Take the space out. I ran the following code from inside TeXStudio, using a User command of pythontex %.tex in the user0 spot (ALT+SHIFT+F1).

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}  
\usepackage{pythontex}
\begin{document}
    \LaTeX

\begin{pycode} 
print ('Hello, \LaTeX')
\end{pycode}
\end{document} 

Don't forget to run pdflatex again after running pythontex.

Also, you must run pythontex test.tex not test.py.

The section of pythontex code that is throwing the latest error is in pythontex3.py in the ...your TeX distribution folder/scripts/pythontex folder. It says:

# Check for compatility between the .pytxcode and the script
if 'version' not in settings or settings['version'] != data['version']:
    print('* PythonTeX error')
    print('    The version of the PythonTeX scripts does not match the last code')
    print('    saved by the document--run LaTeX to create an updated version.\n')
    sys.exit(1)

So it looks like there is an old version setting hanging around somewhere. I'm not intimately familiar with all the settings and locations. Geoff Poore (the author) is a colleague, but he's not in the office right now. I'm sorry I can't give you more assistance immediately.

Related Question