![使用 PythonTeX 运行简单示例失败](https://linux22.com/image/272019/%E4%BD%BF%E7%94%A8%20PythonTeX%20%E8%BF%90%E8%A1%8C%E7%AE%80%E5%8D%95%E7%A4%BA%E4%BE%8B%E5%A4%B1%E8%B4%A5.png)
我尝试使用 PythonTeX v 0.12 beta 版本编译以下示例:
\documentclass[12pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pythontex}
\begin{document}
\py{2+2}
\end{document}
我运行pdflatex
该文件,然后在运行pythontex
该文件时出现以下错误:
C:\Users\Uwe\Documents\python\Scripts\pythontex>pythontex pythntx1
This is PythonTeX v0.12beta
Traceback (most recent call last):
File "c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py", line 48, in
<module>
pythontex.main()
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 2125,
in main
do_multiprocessing(data, temp_data, old_data, engine_dict)
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 1055,
in do_multiprocessing
result = task.get()
File "C:\Python27\lib\multiprocessing\pool.py", line 522, in get
raise self._value
TypeError: must be string without null bytes or None, not str
C:\texlive\2013\bin\win32\runscript.tlu:596: command failed with exit code 1:
这是测试版中的错误还是我做错了什么?
编辑:前六行
以下是 的前六行pythntx1.pytxcode
:
=>PYTHONTEX#py#default#default#0#i####8#
2+2
=>PYTHONTEX:SETTINGS#
version=v0.12beta
outputdir=pythontex-files-pythntx1
workingdir=pythontex-files-pythntx1
现在运行代码会带来不同的错误:
C:\Users\Uwe\Documents\python\Scripts\pythontex>pdflatex pythntx1.tex
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/W32TeX)
restricted \write18 enabled.
entering extended mode
(./pythntx1.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/scrartcl.cls
Document Class: scrartcl 2012/07/29 v3.11b KOMA-Script document class (article)
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/scrkbase.sty
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/scrbase.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/scrlfile.sty
Package scrlfile, 2012/06/15 v3.12 KOMA-Script package (loading files)
Copyright (C) Markus Kohm
))) (c:/texlive/2013/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/scrsize12pt.clo)
(c:/texlive/2013/texmf-dist/tex/latex/koma-script/typearea.sty
Package typearea, 2012/07/29 v3.11b KOMA-Script package (type area)
Copyright (C) Frank Neukam, 1992-1994
Copyright (C) Markus Kohm, 1994-
)) (c:/texlive/2013/texmf-dist/tex/latex/base/fontenc.sty
(c:/texlive/2013/texmf-dist/tex/latex/base/t1enc.def))
(c:/texlive/2013/texmf-dist/tex/latex/base/inputenc.sty
(c:/texlive/2013/texmf-dist/tex/latex/base/utf8.def
(c:/texlive/2013/texmf-dist/tex/latex/base/t1enc.dfu)
(c:/texlive/2013/texmf-dist/tex/latex/base/ot1enc.dfu)
(c:/texlive/2013/texmf-dist/tex/latex/base/omsenc.dfu)))
(c:/texlive/2013/texmf-dist/tex/latex/pythontex/pythontex.sty
(c:/texlive/2013/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix
<2008/02/07> (tvz)) (c:/texlive/2013/texmf-dist/tex/latex/etex-pkg/etex.sty)
(c:/texlive/2013/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(c:/texlive/2013/texmf-dist/tex/generic/xstring/xstring.sty
(c:/texlive/2013/texmf-dist/tex/generic/xstring/xstring.tex))
(c:/texlive/2013/texmf-dist/tex/latex/pgfopts/pgfopts.sty
(c:/texlive/2013/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(c:/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(c:/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex)
))) (c:/texlive/2013/texmf-dist/tex/latex/caption/newfloat.sty)
(c:/texlive/2013/texmf-dist/tex/latex/upquote/upquote.sty
(c:/texlive/2013/texmf-dist/tex/latex/base/textcomp.sty
(c:/texlive/2013/texmf-dist/tex/latex/base/ts1enc.def
(c:/texlive/2013/texmf-dist/tex/latex/base/ts1enc.dfu))))) (./pythntx1.aux)
(c:/texlive/2013/texmf-dist/tex/latex/base/ts1cmr.fd)
(c:/texlive/2013/texmf-dist/tex/latex/xcolor/xcolor.sty
(c:/texlive/2013/texmf-dist/tex/latex/latexconfig/color.cfg)
(c:/texlive/2013/texmf-dist/tex/latex/pdftex-def/pdftex.def
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(c:/texlive/2013/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)))
Package PythonTeX Warning: Missing autoprint content on input line 8.
[1{c:/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./pythntx1.aux) ){c:/texlive/2013/texmf-dist/fonts/enc/dvips/cm-super/cm-super
-t1.enc}<c:/texlive/2013/texmf-dist/fonts/type1/public/cm-super/sfbx1200.pfb><c
:/texlive/2013/texmf-dist/fonts/type1/public/cm-super/sfrm1200.pfb>
Output written on pythntx1.pdf (1 page, 4786 bytes).
Transcript written on pythntx1.log.
C:\Users\Uwe\Documents\python\Scripts\pythontex>pythontex pythntx1
Traceback (most recent call last):
File "c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py", line 41, in
<module>
import pythontex2 as pythontex
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 970
engine_dict[input_family].extension,
^
SyntaxError: invalid syntax
C:\texlive\2013\bin\win32\runscript.tlu:596: command failed with exit code 1:
python.exe c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py pythntx1
编辑20130716:
修复第 969 行的逗号后,我得到
C:\Users\Uwe\Documents\python\Scripts\pythontex>pythontex pythntx1
This is PythonTeX v0.12beta
Traceback (most recent call last):
File "c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py", line 48, in
<module>
pythontex.main()
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 2125,
in main
do_multiprocessing(data, temp_data, old_data, engine_dict)
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 976, i
n do_multiprocessing
keeptemps, hashdependencies)
File "c:\texlive\2013\texmf-dist\scripts\pythontex\pythontex2.py", line 1203,
in run_code
proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=err_file)
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
TypeError: must be string without null bytes or None, not str
C:\texlive\2013\bin\win32\runscript.tlu:596: command failed with exit code 1:
python.exe c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py pythntx1
编辑20130716:
升级到 Python 2.7.5 后,我现在得到:
Upgraded to Python 2.7.5. The old error is gone, but_
pythontex pythntx1
This is PythonTeX v0.12beta
---- Messages for py:default:default ----
* PythonTeX notice
1 message(s) could not be classified
Based on the return code, they were interpreted as errors
* PythonTeX stderr - unknown on line ??:
python: can't open file '<outputdir>\py_default_default.py': [Errno 2] No such
file or directory
--------------------------------------------------
PythonTeX: pythntx1 - 1 error(s), 0 warning(s)
C:\texlive\2013\bin\win32\runscript.tlu:596: command failed with exit code 1:
python.exe c:/texlive/2013/texmf-dist/scripts/pythontex/pythontex.py pythntx1
答案1
PythonTeX v0.12beta 适用于 Python 2.7.3 及更高版本,但不适用于 Python 2.7.2 及更早版本。这是由于 2.7.3 中引入了更改。我将尝试使最终的 0.12 版本适用于所有版本的 Python 2.7。
我对 Python 2.7.2 进行了一些额外的实验,并找到了问题的最终根源。 subprocess.Popen()
不是问题。相反,shlex.split()
不支持 Unicode 输入Python 2.7.3 之前版本。
编辑2013/08/27:PythonTeX v0.12 可以检测 2.7.3 之前的 Python 版本并解决该问题。