5

I cannot get the ExternalEvaluate work for my Python. It says "missing dependencies" for the registration status. I have attached screenshots from Mathematica and Terminal. From the terminal screenshot you can see that I already have "pyzmq" installed. Does anyone have a solution to this?

terminal Mathematica

baker
  • 453
  • 3
  • 6
  • 1
    Use StartExternalSession and specify which exact Python executable you want to use. You have several installations and the one ExternalEvaluate would start does not have the dependencies installed. – Szabolcs Sep 11 '19 at 07:17
  • Thanks for the reply. But the problem for me is that all the Python executables are missing dependencies? Why is that, how to fix it? – baker Sep 12 '19 at 14:18
  • You must specify the path to the exact executable for which you installed the dependency. I don't see that one in the list. – Szabolcs Sep 12 '19 at 15:59
  • Yeah, i am not sure about that too. I have installed Python through Anaconda and also directly from online. Both are missing dependencies. Not sure why. – baker Sep 12 '19 at 18:28
  • 2
    Try this: Activate the anaconda environment you want to use. Make sure the dependencies are installed in this environment. Run which python to get the correct path to the python executable. Use this path with StartExternalSession. See the docs (under Details) for how. – Szabolcs Sep 12 '19 at 20:00
  • You mean something like this – baker Sep 12 '19 at 21:07
  • StartExternalSession[<| "System" -> "Python", "Executable" -> "/usr/local/bin/python3.7" |>] – baker Sep 12 '19 at 21:07
  • It still does not work. could you explain what do you mean by Run which python? – baker Sep 12 '19 at 21:11
  • Use which to find out the correct path, see https://linux.die.net/man/1/which – Szabolcs Sep 13 '19 at 06:16
  • 1
    It worked now! Thanks a lot. – baker Sep 13 '19 at 21:48

1 Answers1

2

The question has not yet receive a formal answer so I put one here from the comments of Szabolcs and baker.

First install pyzmq by opening a terminal window and entering

pip install pyzmq

(the process takes a few minutes). That should be it! In Mathematica, type

FindExternalEvaluators["Python"]

which should show all the Python installations available. Note that the column "Registered" should now indicate "Automatic" for those versions of Python compatible with both Mathematica and pyzmq.

From here, you can run Python code in Mathematica. /if there is a problem, you can specifically specify which version you wan to select with for example:

session = StartExternalSession[{"Python", "Version" -> "2.7.16"}]

Make sure that the version selected is registered.

Denis Cousineau
  • 1,099
  • 6
  • 18
  • Do you know why only some virtual environment would have missing dependencies? I have a working virtual environment (python 3.8). I created a new one and ran pip install pyzmq both inside this environment and outside to be sure (returning "Requirement already satisfied"). It is still saying MissingDependencies. (While it says True for the working environment.) – Kvothe Jun 21 '22 at 14:33
  • Sorry, I have no clue. – Denis Cousineau Jun 22 '22 at 05:27