4

On my macbook, I'm trying to run pythontex from Textmate using % !TEX TS-program = pythontex Here's a minimal document:

% !TEX TS-program = pythontex
\documentclass{article}
\usepackage[makestderr]{pythontex}

\begin{document}
\pyb{print('Python says hi!')}
\end{document}

I want to run pythontex using anaconda python, which is my default python for terminal and Textmate python files.

Everything works fine if I run pdflatex, pythontex, pdflatex from terminal.

However, When I try to typeset the above document within Textmate, the % !TEX TS-program = pythontex line seems to be using Apple's python, 2.7.10 (default, Oct 23 2015, 18:05:06) which leads to an error about pygments not being installed.

Question: How does % !TEX TS-program = pythontex determine what python to use?? Why is it picking something besides my terminal and text mate default?

1
  • If I change PATH according to blog.macromates.com/2014/defining-a-path I get errors due to the fact that pythontex is passed -interaction=nonstopmode as if it were pdflatex. Commented Dec 19, 2015 at 11:12

2 Answers 2

3

TextMate

I found this page http://blog.macromates.com/2014/defining-a-path/ and I went in the preferences of TextMate, changing (or adding) the setting for PATH as in the following picture

enter image description here

After enabling shell escape and running the test file

\documentclass{article}

\begin{document}
\immediate\write18{echo $PATH>\jobname.path}
\end{document}

the .path file that's created shows

/usr/local/bin:/Library/TeX/texbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/<username>/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/bin

However, hitting Command-R shows errors related to pythontex being passed the options

-interaction=nonstopmode -file-line-error

This is, in my opinion, a bug in the LaTeX bundle of TextMate.

If I remove the TS-program line and enable “Use latexmk” in the LaTeX bundle preferences, the correct pythontex call seems to be made.

TeXShop

If you're using the pythontex.engine script distributed with TeXShop, it sets

PATH=~/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/Library/TeX/texbin

It also has a commented out line

 #PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/Library/TeX/texbin

and it's clear that both give preference to /usr/bin/python, that is the Apple distributed one (on my system it is version 2.7.5, because I'm still with 10.9.5 on this machine), unless, of course, you have Python in ~/anaconda/bin.

If you want to use the Python version coming with Homebrew or other independent software distribution, you need to modify the setting of PATH. If your Python is in /usr/local/bin, just comment the first setting of PATH and uncomment the second one, but moving /usr/local/bin earlier than /usr/bin.

The location of pythontex.engine should be in

~/Library/TeXShop/Engines
3
  • you say "both give preferences to /usr/bin/python" but the first one starts with ~/anaconda/bin, which is a Python installation. The anaconda installer can indeed install binaries in user repertory. Commented Dec 19, 2015 at 18:48
  • @jfbu Unless there is a Python executable in ~/anaconda/bin, yes. Commented Dec 19, 2015 at 18:59
  • that would be the default after an anaconda installation; mine is actually in /opt not in ~/ and its bin sub repertory has python (which is a link to python3.4), ipython, spyder (an IDE), etc... Commented Dec 19, 2015 at 20:01
1

You need to prefix the binary path of Anaconda to the value of the PATH variable inside TextMate. For that purpose open TextMatePreferences…Variables and add the variable PATH:

TextMate Preferences

Then remove the line % !TEX TS-program = pythontex from your document. After that add the option -shell-escape and check Use Latexmk inside the bundle preferences (BundlesLaTeXPreferences):

LaTeX Bundle — Preferences

After that both “Typeset & View (PDF)” and “Watch Document” should work as expected.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.