0
$\begingroup$

enter image description here

In the above screenshot, I've shared the installed and registered version of python. However, when I try to use it, it ends up with an error.

res = ExternalEvaluate[session, "import math
  [math.sqrt(i) for i in range(10)]"]

enter image description here

I tried another methods, there also I faced errors

res = ExternalEvaluate[session, "/home/FDM.py"]

enter image description here

enter image description here enter image description here

$\endgroup$
6
  • $\begingroup$ The first command math.sqrt gives an error (unexpected indent) because there are 2 spaces before [math. ... (maybe it was added after pasting). For running a file, following this workflow, File is used. $\endgroup$ Commented Apr 1, 2022 at 12:01
  • $\begingroup$ Was Enter/Return key pressed after import math? Also does something simple like 1 + 1 return a result? Which version of Mma and which OS? $\endgroup$ Commented Apr 1, 2022 at 12:03
  • $\begingroup$ I would not expect the second attempt to be successful as it is not valid Python syntax. Maybe it would work at the Python terminal but the session is at the language parser. $\endgroup$ Commented Apr 1, 2022 at 12:05
  • $\begingroup$ For the third check all your spacing. The Python editor used to make and run the file might be fixing leading/trailing spaces for you before sending to the parser. That is not happening for the external session. $\endgroup$ Commented Apr 1, 2022 at 12:11
  • $\begingroup$ Here is the correct syntax: res = ExternalEvaluate["Python", "import math\n[math.sqrt(i) for i in range(10)]"] $\endgroup$ Commented Apr 1, 2022 at 13:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.