1

My question : How come PythonTex works as long as I don't try to load numpy ?

In the simple code below for instance

MWE

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{float}
\usepackage{pythontex}

\begin{document}

\begin{pycode}

def fib(n): # nth Fibonacci value a, b = 0, 1 for i in range(n): a, b = b, a + b return a \end{pycode}

Did you know that $F_{10} = \py{fib(10)}$?

Did you know that $F_{100} = \py{fib(100)}$?

\end{document}

gives

enter image description here

whereas I get

enter image description here

When I use

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{float}
\usepackage{pythontex}

\begin{document}

\begin{pycode} %import numpy as np %<- I get an error each time I try to load numpy def fib(n): # nth Fibonacci value a, b = 0, 1 for i in range(n): a, b = b, a + b return a \end{pycode}

Did you know that $F_{10} = \py{fib(10)}$?

Did you know that $F_{100} = \py{fib(100)}$?

\end{document}

I compile on Windows 10, TeXmaker, MikteX, Anaconda and run

pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex|
python "C:/Program Files/MiKTeX/scripts/pythontex/pythontex.py" %.tex|
pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex

Reading multiple posts on PythonTeX I understand the answer might be related to my MikTeX and/or Python installation? But strange it works for simple things and creates an error for numpy...

Edit

As mentionned in comment, there might be a problem to find python.tex. So I inputed the full path to python.exe directly in cmd but I get the following error message you might understand better than I do :/

enter image description here

JeT
  • 3,020
  • You should have different versions of Python installed. One version sees numpy whereas the other not. Am I right? – projetmbc Dec 13 '20 at 22:43
  • @ projetmbc You seem to have a cristal ball !! Your comment made me try a where python and bingo You're right. I get two entries :/ Especially a AppData\Local\Microsoft\WindowsApps\python.exe I was not aware of !! – JeT Dec 13 '20 at 22:45
  • You need now to tell to pythontex which version to use. The documentation should explain how to do that. – projetmbc Dec 13 '20 at 22:50
  • @projetmbc Right ! I need to get rid of this one – JeT Dec 13 '20 at 22:50
  • @projetmbc I've just tried to point things to the right python installation as in pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex| C:\tools\Anaconda3\python.exe "C:/Program Files/MiKTeX/scripts/pythontex/pythontex.py" %.tex| pdflatex --shell-escape -synctex=1 -interaction=nonstopmode %.tex but I still get an error. – JeT Dec 13 '20 at 22:55
  • @projetmbc Following your judicious comment I ran directly in cmd the path and got an error message you might understand better than me (i edited my question with a log) – JeT Dec 13 '20 at 23:14
  • 2
    It is late in France. Try to show the message on a Python forum. Your problem seems to be Windows specific. I have to sleep. – projetmbc Dec 13 '20 at 23:18
  • @projetmbc Merci ! à bientot ! – JeT Dec 13 '20 at 23:21

1 Answers1

1

After different checks and thanks to this post and how-do-you-fix-runtimeerror-package-fails-to-pass-a-sanity-check-for-numpy-an.

This error occurs when using python3.9 and numpy1.19.4 So uninstalling numpy1.19.4 and installing 1.19.3 will work.

pip install numpy==1.19.3

And I get the right result loading numppy

enter image description here

JeT
  • 3,020