From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6LxzAKXdu1+CIgAA0tVLHw (envelope-from ) for ; Mon, 23 Nov 2020 16:04:53 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id IP31N6Tdu184FAAA1q6Kng (envelope-from ) for ; Mon, 23 Nov 2020 16:04:52 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EC9889404CC for ; Mon, 23 Nov 2020 16:04:51 +0000 (UTC) Received: from localhost ([::1]:51306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khEKf-0007dD-1Z for larch@yhetil.org; Mon, 23 Nov 2020 11:04:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khEJQ-0007a5-OP for emacs-orgmode@gnu.org; Mon, 23 Nov 2020 11:03:33 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:35480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khEJM-0007aE-WE for emacs-orgmode@gnu.org; Mon, 23 Nov 2020 11:03:30 -0500 Received: by mail-pl1-x636.google.com with SMTP id x15so9063653pll.2 for ; Mon, 23 Nov 2020 08:03:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=01pHpfCRFQ1s5AKx6g9UBeQEH8O/jl2DrfmHkZZZo2k=; b=pQGo49TbQlgIoRkEUm4ssXV6Zr/5xvmjaqFJXxFgKqFvittJRebeqh1YMxWT/FjZMD +2LrRf29d9+ezUkj1qkpPdiwCL1XrIrVWav7gs8ODtKS6rgF98zdjyk19TVJxv1/hzxb Mlw34y8JkhdDBUzyUEq56YLP1x0Na74y5voZg8dZZzuotL5EIrdxUh1KRGaQ6zSwiv6y 5nm16YiVTIMspg06T7OVED6/3rYXCKBF+qAWdKZ3Zt81/gpEiss2Hnvqvbyzt99IqX9W IHY6pmRC6lQE6osBq5nMty1mmK/+m7f7qzFwHSSgNF0gLC0YdskbZgWCTWy3NZVCrdDm fFFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=01pHpfCRFQ1s5AKx6g9UBeQEH8O/jl2DrfmHkZZZo2k=; b=HLgF8viE7sHz0Z4KBA4AvZSYkzSpETtK5xhgZBOsIPlUgXZlk49VQHX0qApK9wam/S cjklTN7BZu3VwVQpY68udTvi0Xdsz4Ehsu6yPClMUwbmQJ7H+SZgMQLw6Z1PPUd+llhz ug3QxrlP1skwbdynPpvBK7GGiIGDx0zBhLDJeda+/XbI9nmQuKj9Sb7EEZ2WabhfgeZ0 gt6fK8lx6zsMmrcPbsMUycGW4XbWirzTLLEksEJSu6a20anWbGgEARb2eRuVnNU11wge DT9HMC/cR8ZheUxJ23ji/Zzbg5jX6CTtxIO/QjbY3vvpgC8SpAzgQEdsw+eczpx7clCm T+Zg== X-Gm-Message-State: AOAM533EEOkfu3NdXEaz783fTs/qkMXRkrLxzV1rGOsaY+MW5EddmLDb ebH/B+0ZCmmHoRbKCyD2Vd7JL2S1hmBzp7Hen4A= X-Google-Smtp-Source: ABdhPJzLveaUisyfWG46jUrvhnqv3MaJm2XdKew/lPMgyegb1a6FHDEkV0zqKma3KxCon76o1JREBB+xUJ496CwmbVM= X-Received: by 2002:a17:902:8a87:b029:d7:cf56:ce1f with SMTP id p7-20020a1709028a87b02900d7cf56ce1fmr330954plo.22.1606147406255; Mon, 23 Nov 2020 08:03:26 -0800 (PST) MIME-Version: 1.0 References: <87eekkt6s9.fsf@fastmail.fm> In-Reply-To: <87eekkt6s9.fsf@fastmail.fm> From: John Kitchin Date: Mon, 23 Nov 2020 11:03:15 -0500 Message-ID: Subject: Re: ob-python: import local package into a session To: Joost Kremers Content-Type: multipart/alternative; boundary="0000000000009b593b05b4c85549" Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=johnrkitchin@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=pQGo49Tb; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.11 X-TUID: pB+ruWJCsJ/v --0000000000009b593b05b4c85549 Content-Type: text/plain; charset="UTF-8" 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 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 > > --0000000000009b593b05b4c85549 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I usually do that by either having the py file in the work= ing directory of the session, in which case you simply import it.

<= /div>
Alternatively something like this in python:

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

you could also ap= pend to sys.path if that matters.

John

-----------------------------= ------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Department = of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 152= 13
412-268-7803


On Mon, Nov 23, 202= 0 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 sessio= n
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&#= 39;t
installed system-wide?

What I'm trying to do is to import a Python file with a bunch of utilit= y
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 se= em 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 b= e interested
as well.

TIA

Joost


--
Joost Kremers
Life has its moments

--0000000000009b593b05b4c85549--