1
$\begingroup$

I want to use specific python libraries via the Mathematica frontend. This is possible as follows

In[30]:= ExternalEvaluate["Python", "from sympy import isprime; isprime(7)"]

Out[30]= True

However, if I directly try to evaluate the same using > at the beginning of a line to use an external code cell, this does not work. For instance,

> from sympy import isprime; isprime(7)

gives as output,

Failure[[WarningSign] Message: No module named 'sympy' Tag: PythonError ]

Any ideas on how to make this work from external code cells.

$\endgroup$
3
  • 1
    $\begingroup$ It works for me on 13.2 with some modules e.g os, sys, math and so on. Maybe it's something to do with the PYTHONPATH. Try import sys; sys.path in both ExternalEvaluate and the code cell and see if there's a difference. $\endgroup$ Commented Jan 5, 2023 at 22:55
  • 1
    $\begingroup$ If I pip install sympy globally (as admin) then importing sympy works and both evaluate to True, so either you're on an older Mathematica where there's a discrepancy between the two choices of path, or something is wrong with your python setup. $\endgroup$ Commented Jan 5, 2023 at 23:20
  • 1
    $\begingroup$ @flinty: Thanks a lot. Yes there was a difference in the sys.path between the two as the external code cell was accessing a different python distribution. After unregistering the problematic one, things are fine. $\endgroup$ Commented Jan 6, 2023 at 2:10

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.