0

These are my first attempts to plot graph in Python. Following this example , I tried a very simple graph

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()
plt.savefig('python-matplot-fig.png')
return 'python-matplot-fig.png' # return filename to org-mode

I got an error :

Traceback (most recent call last):
  File "<stdin>", line 13, in <module>
  File "<stdin>", line 3, in main
ImportError: No module named matplotlib.pyplot

Whereas I have the python installed and running on my system.

On VsCode, it is calculated

enter image description here

I use spacemacs python layer

  dotspacemacs-configuration-layers
   '(
     (python
      :variables
      python-backend 'anaconda
      python-format-on-save t
      python-sort-imports-on-save t)
3
  • Try without a :session header arg. Python processing in Org bbel is subtly different between sessions and non-sessions. Or use :session but get rid of the return in your code (which is what the linked page shows). Also, this tends to be fragile, so depending on your version of Org mode, you might (or might not) hit other problems. You should post the version as part of your question. – NickD Dec 16 '20 at 14:16
  • 2
    I'd guess Emacs is using a different Python? Perhaps the system Python which does not have matplotlib installed by default? – mankoff Dec 16 '20 at 21:17
  • @NickD : org 9.3.6 – user1683620 Dec 17 '20 at 10:51
1

The python version used by org-babel was 2.7.8

To use the "last" version of Python on my system, I used in my init.el file

(setq org-babel-python-command "python3")

then all librairies installed by pip in my terminal were usable

1
  • @mankoff had it right. – NickD Dec 17 '20 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.