手塚兎月の備忘録

チェス、ポケモン、数学、その他

Latex内でPythonが動かない

okumuralab.org

\documentclass{jsarticle}

\usepackage{pythontex}

\begin{document}

 

\begin{pycode}

def fibn(n):

if n < 3:

return 1

else:

return fibn(n-2) + fibn(n-1)

\end{pycode}

 

フィボナッチ数列 1, 1, 2, 3, 5, \ldots\ の10番目は\py{fibn(10)}である。

 

\end{document}

 

これを実行すると

フィボナッチ数列 1, 1, 2, 3, 5, \ldots\ の10番目は??である。

となる。

jupyter Notebookで

pip install pygments行って無事に入れたが何故か?