Message Boards Message Boards

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

How to import Python Libraries with ExternalEvaluate?

Posted 2 years 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 2 years 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
Posted 2 years 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
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