I am trying to install pythontex on Ubuntu 13.04. but cant find the way how. Downloaded ZIP from http://www.ctan.org/pkg/pythontex.

Tried to follow instructions but unfortunately something went wrong.

Is there any simpler way to do it? If not, can you please help me by writing instructions step by step?

RE-EDITED: After installing pythontex when I try to compile e.g.



def fib(n):    

a, b = 0, 1  
for i in range(n):  
a, b = b, a + b  
return a  


I get error:

! LaTeX Error: Environment pycode undefined.  
! You can't use `macro parameter character #' in horizontal mode.  
! LaTeX Error: \begin{document} ended by \end{pycode}.  

File List
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
inputenc.sty 2008/03/30 v1.1d Input encoding file
utf8.def 2008/04/05 v1.1m UTF-8 support for inputenc
t1enc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
ot1enc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
omsenc.dfu 2008/04/05 v1.1m UTF-8 support for inputenc
amsmath.sty 2000/07/18 v2.13 AMS math features
amstext.sty 2000/06/29 v2.01
amsgen.sty 1999/11/30 v2.0
amsbsy.sty 1999/11/29 v1.2d
amsopn.sty 1999/12/14 v2.01 operator names
amsfonts.sty 2009/06/22 v3.00 Basic AMSFonts support
amssymb.sty 2009/06/22 v3.00

  • Where did the installation go wrong? You need to install things in the right directories.
    – jon
    Dec 27 '13 at 16:16
  • There is no pythontex.sty so according to instructions (pythontex.pdf) I should start pythontex.ins and get pythontex.sty if understand it correctly. But I can't get pythontex.sty from it. So downloaded .sty from and start pythontex_install_texlive.py. It gives me some options during installation and don't know what to do with it.
    – benjamin
    Dec 27 '13 at 16:24
  • That's not enough: you need to install many different files for pythontex to work. See the README. You should download the entire zip file (direct link: here]).
    – jon
    Dec 27 '13 at 17:12
  • unfortunately, don't know how to do it. after unzip I've got pythontex.sty from pythontex.ins.
    – benjamin
    Dec 27 '13 at 18:19
  • 1
    Option 1: find the root of your 'main' texmf tree with kpsewhich --var-value TEXMFMAIN; option 2: find the root of your 'personal' texmf tree with kpsewhich --var-value TEXMFHOME (probably ~/texmf). I refer to your choice as 'TEXMF'. According to pythontex.pdf (see p. 8 in my version), you need to move the doc files to TEXMF/doc/latex/pythontex (6 files total); the script files to TEXMF/scripts/pythontex/ (8 files); the source files to TEXMF/source/latex/pythontex; and the style file to TEXMFMAIN|TEXMFLOCAL/tex/latex/pythontex. Then do sudo texhash & create the symlinks.
    – jon
    Dec 27 '13 at 18:32

The steps for installing are:

  1. Download the package
  2. Right click the file and click on Extract Here.
  3. Open a terminal (Ctrl+Alt+T) and run these commands:

    cd Downloads/pythontex
    latex pythontex.ins
    md ~/texmf
    md ~/texmf/tex
    mv * ~/texmf/tex
    chmod +x ~/texmf/

And the package will be installed. To compile a file:

pdflatex foo.tex
~/texmf/pythontex.py foo.tex
pdflatex foo.tex

I installed the package just now with these commands and now it is working for me.

  • This is not recommended. Your ~/texmf directory should be structured to mirror the TeX Directory Structure of your actual install, which is in fact correctly described in the pythontex manual.
    – jon
    Dec 28 '13 at 22:19

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.