Message Boards Message Boards

0
|
2786 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to import Python Libraries with ExternalEvaluate?

Posted 1 year ago

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,

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

How can we make this work from within external code cells?

POSTED BY: Asim Ansari
2 Replies
Posted 1 year ago

Thanks. This was solved by unregistering one of the python distributions that I had on the system. The two methods were accessing different distributions.

POSTED BY: Asim Ansari
Posted 1 year ago

You should be able to use StartExternalSession to create an ongoing Python session that you can import things into before doing your main ExternalEvaluate calls.

This should also make the repeated calls a bit faster, so that is a plus.

POSTED BY: Alec Graves
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract