emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Joost Kremers <joostkremers@fastmail.fm>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: ob-python: import local package into a session
Date: Mon, 23 Nov 2020 11:03:15 -0500	[thread overview]
Message-ID: <CAJ51ETqFOJxS_G5+SBBnucryC8+kQ8=t7-N+ONqPTR3DoiAU1w@mail.gmail.com> (raw)
In-Reply-To: <87eekkt6s9.fsf@fastmail.fm>

[-- Attachment #1: Type: text/plain, Size: 1581 bytes --]

I usually do that by either having the py file in the working directory of
the session, in which case you simply import it.

Alternatively something like this in python:

import sys
sys.path.insert(0, '/path/to/dir/with/myfile.py')
import myfile

you could also append to sys.path if that matters.

John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Mon, Nov 23, 2020 at 10:49 AM Joost Kremers <joostkremers@fastmail.fm>
wrote:

> Hi all,
>
> If I have an Org file with Python source blocks, I can run them in a
> session
> with the `:session` header arg. That way, I can include packages installed
> in
> `site-packages` and have them available in all code blocks. But is there a
> way
> to import my own packages into a session? In particular, packages I haven't
> installed system-wide?
>
> What I'm trying to do is to import a Python file with a bunch of utility
> functions into the ob-python session. I thought this might be possible if
> I'd
> structure my code as a regular Python package, because that works if I
> want to
> import my utility functions into another Python file. But it doesn't seem
> to
> work for the ob-python session.
>
> Is there a way to achieve this? I don't *have* to structure my utility
> functions
> as a Python package, so if there's another way of doing this, I'd be
> interested
> as well.
>
> TIA
>
> Joost
>
>
> --
> Joost Kremers
> Life has its moments
>
>

[-- Attachment #2: Type: text/html, Size: 2355 bytes --]

  reply	other threads:[~2020-11-23 16:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 15:46 ob-python: import local package into a session Joost Kremers
2020-11-23 16:03 ` John Kitchin [this message]
2020-11-23 16:20 ` Jack Kamm
2020-11-23 16:21   ` Jack Kamm
2020-11-23 22:47   ` Joost Kremers
2020-11-24 12:23 ` Maxim Nikulin
2020-11-24 13:35   ` Joost Kremers
2020-11-24 14:24     ` Jack Kamm
2020-11-24 18:40       ` Tom Gillespie
2020-11-25 12:58       ` Joost Kremers

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='CAJ51ETqFOJxS_G5+SBBnucryC8+kQ8=t7-N+ONqPTR3DoiAU1w@mail.gmail.com' \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=joostkremers@fastmail.fm \
    /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).