I have the following 'test.py' written in Python:
import numpy as np
f = open('normals.txt', 'r')
content = f.read()
print(content)
and I want to execute it from Mathematica using:
session = StartExternalSession["Python"];
ExternalEvaluate[session, File["~/test.py"]]
but when I run this, I get the error:
Following the answer given in Using local variables in ExternalEvaluate Python, I have checked that numpy
is already installed, by running FindExternalEvaluators[]
where I get a table with Python
, Python-NumPy
, Python-PIL
, etc. so I guess everything is fine. Now, I should run:
session = StartExternalSession["Python-NumPy"]
However, it returns a failure with the session specification, StartExternalSession::invalidSpec
. How can I ExternalEvaluate
a Python code which has import numpy
in it?
ExternalEvaluate[session, "import sys; print(sys.executable)"]
and see whether the path is correct. Did you installnumpy
via pip? Do you use conda environments? $\endgroup$