1

After installing the package pythontex via latex pythontex.ins, I tried the following example to test it:

\documentclass[10pt,a4paper]{article}  
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}  
\usepackage{pythontex}  
\listfiles  
\begin{document}
\begin{pycode}  
print "Hello \Latex "
\end{pycode}  
\end{document} 

First step was pdflatex PythonExample1.tex which I got the following message:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
restricted \write18 enabled.entering extended mode
(./PythonExample1.tex
LaTeX2e <2011/06/27>
Babel <3.9h> and hyphenation patterns for 4 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def
(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty)     (./pythontex.sty
(/usr/share/texlive/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline   fix 
<2008/02/07> (tvz) (/usr/share/texlive/texmf-  dist/tex/latex/graphics/keyval.sty
)) (/usr/share/texlive/texmf-dist/tex/latex/etex-pkg/etex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/share/texlive/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/share/texlive/texmf-dist/tex/latex/pgfopts/pgfopts.sty
(/usr/share/texmf/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/share/texmf/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/share/texmf/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex))))
(/usr/share/texlive/texmf-dist/tex/latex/caption/newfloat.sty)
(/usr/share/texlive/texmf-dist/tex/latex/currfile/currfile.sty
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/share/texlive/texmf-dist/tex/latex/filehook/filehook.sty))
(/usr/share/texlive/texmf-dist/tex/latex/upquote/upquote.sty))
(./PythonExample1.aux) (/usr/share/texmf/tex/latex/xcolor/xcolor.sty
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)))
No file pythontex-files-PythonExample1/PythonExample1.pytxmcr.
Run PythonTeX to create it.
(./PythonExample1.aux)

*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    2013/01/14 v2.14 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    2013/01/14 v3.01 Basic AMSFonts support
amssymb.sty    2013/01/14 v3.01 AMS font symbols
pythontex.sty    2014/07/17 Version\unhbox\voidb@x \penalty \@M \ {}0.14 
fancyvrb.sty    2008/02/07
keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
etex.sty    1998/03/26 v2.0 eTeX basic definition package (PEB)
etoolbox.sty    2011/01/03 v2.1 e-TeX tools for LaTeX
xstring.sty    2013/10/13  v1.7c  String manipulations (C Tellechea)
pgfopts.sty    2011/06/02 v2.1 LaTeX package options with pgfkeys
pgfkeys.sty    
pgfkeys.code.tex
newfloat.sty    2013/05/11 v1.1-91 Defining new floating environments (AR)
currfile.sty    2013/02/01 v0.7b Provides the file path elements of the   current
input file
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
filehook.sty    2011/10/12 v0.5d Hooks for input files
upquote.sty    2012/04/19 v1.3 upright-quote and grave-accent glyphs in  verbat
im
xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
supp-pdf.mkii
***********

)
No pages of output.
Transcript written on PythonExample1.log.

After that was pythontex PythonExample1.tex to get the following error message:

Traceback (most recent call last):
File "/usr/bin/pythontex", line 42, in <module>
import pythontex2 as pythontex
File "/usr/share/texlive/texmf-dist/scripts/pythontex/pythontex2.py", line  61, in <module>
from pygments.styles import get_all_styles
ImportError: No module named pygments.styles

which is because that pygments is not installed. After installing it I get the following error message

----  Messages for py:default:default  ----
* PythonTeX stderr - error on line 11:
File "<outputdir>/py_default_default.py", line 50
print "Hello \Latex"
                     ^
SyntaxError: invalid syntax

--------------------------------------------------
PythonTeX:  PythonExample1 - 1 error(s), 1 warning(s)

Finally, even if I try pdflatex PythonExample.tex again, no pdf file will be generated. I am using Ubuntu 14.04 with Python 2.7.6 Any help!

  • What version of Pygments do you have? You can probably get this by running pygmentize -V at the command prompt. – G. Poore Aug 12 '14 at 22:02
  • @G.Poore Opps, it is not installed. I just installed and edit the post. Thanks – abd Aug 19 '14 at 19:37
2

You are using print as a statement, so you need

\usepackage[pyfuture=none]{pythontex}

By default, several things are imported from __future__ (absolute_import, division, print_function); this disables the automatic import. Also, you will want to use a raw string or escape the backslash (\\LaTeX)

Alternatively, you could use print("Hello \\LaTeX").

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.