I am trying to import a Python function or execute a Python script from inside Mathematica, but the ExternalEvaluate
command drives me nuts.
I proceed cautiously with the following Python test module, named "test.py":
def test():
print("Test")
print("Hello")
I checked that the module can be found and tried it successfully from the CMD command line:
python
from test import test
Using Import
in Mathematica also works:
Import["!python g:\\p\\python37\\test.py", "String"]
But then with ExternalEvaluate
I first made sure that the Python connection works as follows, which works OK:
ExternalEvaluate["Python", "2+3"]
However, the following gives Exception: Import Error. EvaluationFailure
:
ExternalEvaluate["Python", "from test import test"]
The same happens if I use a session:
ses = StartExternalSession["Python"]
ExternalEvaluate[ses, "from test import test"]
I would be glad for a hint what I am doing wrong
os.getcwd()
andsys.path
.ExternalEvaluate
might not have those right to find it. Also checksys.version
to make sure it's 3.7. $\endgroup$