emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Prof. Dr. Johanna May" <johanna.may@th-koeln.de>
To: emacs-org list <emacs-orgmode@gnu.org>
Subject: ipython integration fails
Date: Wed, 16 Oct 2019 13:17:28 +0200	[thread overview]
Message-ID: <874l09os6v.fsf@th-koeln.de> (raw)


Hi everybody,

I am creating lecture notes including some python snippets. Now, in
order to teach jupyter notebook use I would like to include just the
same code as in a python snippet in an ipython snippet.

However ipython blocks don't work in my set up and I could not figure
out which dependency or config line I might need to add in order to do
this properly (and scimax also creates errors, but since I have my own
config running I thought ipython might  already do the job).

The ipython snippet I used is:
#+BEGIN_SRC ipython :session :results raw drawer
  %matplotlib inline
  import matplotlib.pyplot as plt
  import numpy as np
#+END_SRC

The error message is:
Traceback (most recent call last):
  File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 60, in <module>
    c = create_client(args.conn_file)
  File "/home/username/.emacs.d/elpa/ob-ipython-20180224.953/client.py", line 43, in create_client
    cf = find_connection_file('emacs-' + name)
  File "/usr/lib/python3.6/site-packages/jupyter_client/connect.py", line 218, in find_connection_file
    raise IOError("Could not find %r in %r" % (filename, path))
OSError: Could not find 'emacs-default' in ['.', '/run/user/1000/jupyter']

Maybe I do not need ipython anyway. What works are python code snippets
like the following one. Minted exports both, code and results and they
are both displayed in the pdf slides/manuscript (using lualatex,
beamerarticle etc.)

#+begin_src python :results output :session :exports both
import time
time.sleep(3)
#+end_src

However, then, what does not work properly is several code blocks in one
session, e.g.

(1)
#+begin_src python :results output :session :exports both
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import seaborn as sns
sns.set(style="darkgrid")
#+end_src

(2)
#+begin_src python :results output :session :exports both
df = pd.read_csv('./household_data_1min_singleindex.csv')
#+end_src

(3)
#+begin_src python :results output :session :exports both
zeit=df.utc_timestamp.apply(lambda x: dt.datetime.strptime(x, "%Y-%m-%dT%H:%M:%SZ"))
#+end_src

(4)
#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figu" ".png"),fontsize=fs :exports both
plt.rcParams.update({'font.size':fontsize})
rcParams.update({'figure.autolayout': True})
plt.plot(zeit,df.DE_KN_residential2_washing_machine)
plt.savefig(matplot_lib_filename)
matplot_lib_filename
#+end_src

I do not like the fact that plt.rcParams.update and other lines that
jupyter does not need get exported - is there a simple way to exclude
certain lines from export?

And I do get in serious trouble when I add a second data set (another csv) and do
further analysis steps - all graphics then look the same and bad and do
not represent the actual result of the code block. It seems that all get
the same wrong name and then at each graphics location this same png
gets displayed. 

So, maybe there is a good tutorial on using sessions in ob-python or
some other hint that I could use?

Is there a way to restart the (python) kernel with some header message
in the src block?

Thank you very much,

Cheers,

J. May

             reply	other threads:[~2019-10-16 11:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 11:17 Prof. Dr. Johanna May [this message]
2019-10-16 15:46 ` ipython integration fails John Kitchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874l09os6v.fsf@th-koeln.de \
    --to=johanna.may@th-koeln.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).