PythonTex stderr

PythonTex stderr

我是 pythontex 新手。我可以运行简单的 python 代码。但是,稍微复杂一点的东西就会出错。

我收到的错误如下:

This is PythonTeX 0.16

----  Messages for py:default:default  ----
* PythonTeX stderr - error on line 211:
    File "<outputdir>\py_default_default.py", line 62
      MW= 18e-3 u.kilogram/ u.mole
                ^
  SyntaxError: invalid syntax

--------------------------------------------------
PythonTeX:  notes - 1 error(s), 0 warning(s)

C:\texlive\2018\bin\win32\runscript.tlu:803: command failed with exit code 1:
python.exe c:\texlive\2018\texmf-dist\scripts\pythontex\pythontex.py notes.tex

有错误的代码部分是:

\begin{pycode}
import math
from pint import UnitRegistry
u = UnitRegistry()
alpha = 0.04
sigmaW = 72.86e-3 * u.newton / u.meter
mu    = 8.9e-4 * u.pascal * u.second
densityW = 1000 * u.kilogram / (u.meter ** 3)
densityIPA = 1000 * u.kilogram / (u.meter ** 3)
densityEtoh = 1000 * u.kilogram / (u.meter ** 3)
H = 1e-6 * u.meter
W = 28e-6 * u.meter
L= 32e-6 * u.meter
MW= 18e-3 u.kilogram/ u.mole
MIPA= 60.1e-3 u.kilogram/ u.mole
MEtoh= 46.07e-3 u.kilogram/ u.mole
R0=8.31446 u.joule / (u.mole * u.kelvin)
T0= 298 u.kelvin
N= 10
D0=2.4e-5 (u.meter ** 2)/(u.second)
C0=17.08e-3 u.kilogram/(u.meter ** 3)
tauevW=(densityW * N * R0 * T0 * (W **3))/(6* math.pi * D0 * C0 * sigmaW * MW)
\end{pycode}

有谁知道如何解决这个问题?

答案1

问题在于第 62 行的数字和单位之间缺少乘号。请注意,后续行中也重复出现此省略。以下内容添加了运算符,并且执行没有问题。

\begin{pycode}
import math
from pint import UnitRegistry
u = UnitRegistry()
alpha = 0.04
sigmaW = 72.86e-3 * u.newton / u.meter
mu    = 8.9e-4 * u.pascal * u.second
densityW = 1000 * u.kilogram / (u.meter ** 3)
densityIPA = 1000 * u.kilogram / (u.meter ** 3)
densityEtoh = 1000 * u.kilogram / (u.meter ** 3)
H = 1e-6 * u.meter
W = 28e-6 * u.meter
L = 32e-6 * u.meter
MW = 18e-3 * u.kilogram/ u.mole
MIPA = 60.1e-3 * u.kilogram/ u.mole
MEtoh = 46.07e-3 * u.kilogram/ u.mole
R0 = 8.31446 * u.joule / (u.mole * u.kelvin)
T0 = 298 * u.kelvin
N = 10
D0 = 2.4e-5 * (u.meter ** 2)/(u.second)
C0 = 17.08e-3 * u.kilogram/(u.meter ** 3)
tauevW = (densityW * N * R0 * T0 * (W **3))/(6* math.pi * D0 * C0 * sigmaW * MW)
\end{pycode}

相关内容