0

Setup:

  1. Emacs 25.2.1 on Windows 10
  2. Pymacs 0.25
  3. Anaconda Python 3.5.1

Pymacs is running fine. I can run pymacs-eval and pymacs-exec commands successfully from Emacs. For example, evaluating the following works:

(require 'pymacs)    
(pymacs-exec "from scipy.stats import norm;")
(pymacs-exec "import numpy as np;")
(pymacs-exec "np.set_printoptions(threshold=np.nan);")
(pymacs-eval "norm.ppf(0.95)")

The last line returns

1.6448536269514722

The problem I am having is that some standard Python 3.x statements are returning something strange back to Emacs. In particular, if I run

(pymacs-eval "import numpy as np;")
(pymacs-eval "np.max(np.array([[1,1],[2,4]]))")

I get back

(pymacs-python . 1479)

If you run

(pymacs-load "numpy" "np-")
(np-max (np-array '((1 1) (2 4))))

The last line returns

(pymacs-python . 1479)

This seems to happen whenever I try passing any type of list from Emacs Lisp to Python via Pymacs. Does anybody know what these "(pymacs-python . n)" cons cells mean?

1 Answers1

0

It took quite a bit of work to find the answer. The issue arises when Pymacs does not understand the structure produced by a particular Python function. In the case of Numpy, Pymacs has NO clue how to parse Numpy arrays. The trick is to convert the numpy arrays into standard Python lists.

Here is an example:

(require 'pymacs)
(pymacs-exec "import numpy as np")
(pymacs-eval "np.ndarray.tolist(np.asarray([[1,2],[3,4]]))")

This will produce

'((1 2) (3 4))

Sincerely,

Pablo