5

I am very new to LaTeX. I need to run python package in LaTeX but I can't. I use MiKTeX 2.9 under Windows 7 but the programs gives me this error:

Latex error: ! I can't find file `bin/**filename**.py.out'.

Latex Error: Emergency stop.<read 2> \ end{python}
0

4 Answers 4

3

At the moment python.sty is not in MikTeX package repository. You would have to install it manually.

You can download python.sty from people who have saved the original python.sty by Martin R. Ehmsen. This (bitbucket) is one of such places.

Then copy python.sty to your working directory.

This python.sty needs a python interpreter. You need to install one on Windows. Then modify python.sty to call python.exe instead of /usr/bin/python. I cannot confirm if this would work or not.

This thread on tex.stackexchange.com shows that such modification is possible and provides a version of python.sty modified to work on Windows.

If all goes well you can move it to the local texmf tree as described in MikTeX manual and update path databases.

3
  • I am sorry but didn't understand what to do with the interpreter. I have already installed python 2.7. Now what do i have to do?
    – JPV
    Apr 30, 2012 at 15:01
  • Open the python.sty and make sure that the path to python.exe is the correct one.
    – Philipp
    Apr 30, 2012 at 16:11
  • I add the -enable-write28 but it still does not runs. But where it is writen the path to python? Which line? Because I have not found anything yet.
    – JPV
    Apr 30, 2012 at 22:46
3

There are several ways to run python through LaTeX. The first python.sty file is a bit outdated, I would recommend the updated version from Noon Silk: python.sty on github.

Alternatively there is also SympyTeX, which is written to include the output of the python sympy package into LaTeX documents but works nicely with pure python as well.

Both of these packages are not included on CTAN or MiKTeX.

In both cases LaTeX needs to run your python executable, so it has to be included in the current path. Additionally you have to allow LaTeX to run other executables, e.g. via the --enable-write18 parameter.

2

Alexander's answer was the one got me going. The python.sty file from python.sty on github worked fine when I changed line 61 from:

cat \@pythoninclude\space bin/\jobname.py | python > bin/\jobname.py.out 2> bin/\jobname.py.err

to:

 python \jobname.py > \jobname.py.out 2> \jobname.py.err

As you can see I also removed the bin folder. So I also changed line 63 from:

\immediate\input bin/\jobname.py.out}

to:

\immediate\input \jobname.py.out}

Using this .sty file and adding -enable-write18 parameter to the command line of pdflatex worked for me.

1
1

My PythonTeX package is in beta, but it works very well under Windows. It allows fast execution of Python code (only modified code is executed, and code runs in parallel). Python error messages are synchronized with the LaTeX document to give correct line numbers. Also, code can be typeset with built-in access to Pygments.

3
  • Your package looks very promising, I will definitely try it out soon!
    – Alexander
    May 1, 2012 at 15:33
  • I'm having some problems using the package on Windows 10 with MiKTeX. I cloned the repository, and ran python pythontex_install.py as administrator. Then I do \usepackage[T1]{fontenc}, \usepackage[utf8]{inputenc} and \usepackage{pythontex}in the preamble. Then in the document, as a test, I have \begin{pycode}, print(0) and \end{pycode} on separate rows. However, when I run pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape <tex-file> I get an error: ´! Paragraph ended before \FV@BeginScanning was complete.´ and further down I suspect you've forgotten a `}'. Oct 21, 2017 at 18:35
  • By the way, I'm using Python 3.5.3. Oct 21, 2017 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.