# Pythontex don't work ? why?

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?

• ...that should probably be \LaTeX, not \Latex. – Werner Jul 20 '15 at 18:10
• Thanks for your answer i think i's a more complex solution because when i chnage it i've got :c:\texlive\2015\bin\win32\runscript.tlu :680 :c:\texlive\2015\bin\win32\runscript .tlu:650 : program not found (not part of Tex LIve) :python.exe – fred62 Jul 20 '15 at 18:23
• You need to have a working version of Python, which is not provided by pythontex. See python.org/downloads – egreg Jul 20 '15 at 18:54
• thanks for the answer i already have python v 3.4 on my computer and it seems to work ? – fred62 Jul 20 '15 at 19:27
• Verify your paths are correct by running from the command line a known working *.py program saved in the same folder as that *.tex. – R. Schumacher Jul 20 '15 at 19:36

## 2 Answers

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.

• i have corrected the issue \LaTeX and the space it seems that i progress now i have the error This is PythonTex 0.14 *PythonTex error the version of the PythonTexscripts does not match the last code saved by the document – fred62 Jul 20 '15 at 20:29
• Sorry. I didn't get a notification that there was a comment. See my addition on the last line of my answer. I also suggest that you start with a clean setup. If your TeX file is named test.tex, delete every test.* file in the folder except test.tex Also delete the folder pythontex-files-test. Then run your pdflatex test.tex, pythontex test.tex, pdflatex test.texsequence and see if that works. – Bill N Jul 21 '15 at 3:28
• No problem bill thanks for your answer i don't find the folder python-files-test where it is ? but i try to clean up everything else but allways have the same error message with the three compilation sequence ...at 2nd compilation .... i also try with a new file test1 with the same content it didn't work ... some ideas ? – fred62 Jul 21 '15 at 12:40
• That's odd. If pythontex worked properly then it would create a subfolder in the folder where your tex file is. Note that it would be pythontex-files-test, not python-files-test. As far as the error you're seeing, I can't reproduce it so it must have something to do with your installation, either Python or the pythontex package. I would suggest downloading pythontex again and rehashing your TeX installation. Maybe @G.Poore can jump in here with an idea. – Bill N Jul 21 '15 at 13:18
• well with erase all the files of the installation and another installation rehashing texlive the problem is the same what's wrong with that ? – fred62 Jul 21 '15 at 15:37

Make sure that you have the following lines in .tex file:

\usepackage{pythontex}

\printpythontex

....

\begin{pycode}

print("Arbitrary text or results from the python code")

\end{pycode}

....


This is what you need at minimum in the tex code. Then:

1. Compile LaTeX file, for example demo.tex, in TeXstudio F6

2. Compile Python code. Easiest, open command window and run: pythontex demo.tex

3. Compile LaTeX file again in TeXstudio F6.

It should work. If you have problems in you Python code, Python compilation will tell you what needs to be corrected.