From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6HS0DApUvV9rBwAA0tVLHw (envelope-from ) for ; Tue, 24 Nov 2020 18:42:18 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eFmjCApUvV8TWwAAB5/wlQ (envelope-from ) for ; Tue, 24 Nov 2020 18:42:18 +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 8FA6B9404C2 for ; Tue, 24 Nov 2020 18:42:17 +0000 (UTC) Received: from localhost ([::1]:41102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khdGZ-0004hm-CM for larch@yhetil.org; Tue, 24 Nov 2020 13:42:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khdFJ-0004hd-3z for emacs-orgmode@gnu.org; Tue, 24 Nov 2020 13:40:57 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:42670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khdFH-0004wa-97 for emacs-orgmode@gnu.org; Tue, 24 Nov 2020 13:40:56 -0500 Received: by mail-wr1-x430.google.com with SMTP id l1so23348711wrb.9 for ; Tue, 24 Nov 2020 10:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DX89zy5Rr0KT4DOG9BgGGtVsjIo/2nYmQQ/97yCbkoE=; b=oqjEeG8x5hG5TNmO9NR/+xYEl/qeZQIqrRVO8/DlZUR5qnq6IeaL2XN6YkJE9TgJ5Z ad2MAtI4AeYhU0j1YkNiHpjqJQy97iwItT30I3+ZdvwsrUsR7uyNNjt1Rbdga6W1Luj3 vBVXnxySOB1g77TQZswHiu/h+NfXxqz5J2tPVn82yOb+CIXn1wfRzaoT+5rd231T/u4L w/QePiwBeVDHgNMqDKE0sLH4CjNJbVonWPWnGm2EERj0fSL8AwzhBnBBWnTJCxqptDlv WscWOZxKVjCuSjm9ZKiu/NDR9eXmmPXIIJRH/3ZaydLa4Ss3iRdOMg1X/1K0bgJFzP7d Mkag== 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=DX89zy5Rr0KT4DOG9BgGGtVsjIo/2nYmQQ/97yCbkoE=; b=fjf7s5oLs6PI/Jwx3/D5GG4cUX0WioZatC04krxq9UZvpyGJR3MysB+ZyyKNEInT7n jOiLfA42OaVg/+gj3pEs882k3MvL2KVmfqtuVxjZzJ4p/9ZUVH6BkP+QEvO7FoC9C52G EsfwnnGQY0ySB0R+sAs1vqnwUqtEjuqsuo84gYm5r6xONrMQtC5rQmwZZhKjmmfRjXd9 ohRC5vMGqKiBVGXVAmaKdbkI3s7NXxFv5owfQhVIc9bhtCyGkC5kypZGGlI2JOryDn1y 84lvHgvrVazhiAgq9n+u+seFADKRkiemtKRTz9uJEViNz8UAXC4VJA8tc/1W0oVcjH4U Z1EQ== X-Gm-Message-State: AOAM531sIqCruYM2gH040/5nQtahTygGzX7jMY2tYx0ZREG38DWsuRG0 aVE6pmO0DmPWrWhD8xzBjYOBGJszdddbKtq+e90= X-Google-Smtp-Source: ABdhPJz36D8khrT7xBpQYm2egbmHxWLg0H9rPs3pkgdT3If4P93JzJe39jbJaYJM7zQU2gq8yjICI74isrqTMFvwagE= X-Received: by 2002:adf:f783:: with SMTP id q3mr6655452wrp.88.1606243253576; Tue, 24 Nov 2020 10:40:53 -0800 (PST) MIME-Version: 1.0 References: <87eekkt6s9.fsf@fastmail.fm> <87zh36dgia.fsf@fastmail.fm> <87d0026deg.fsf@gmail.com> In-Reply-To: <87d0026deg.fsf@gmail.com> From: Tom Gillespie Date: Tue, 24 Nov 2020 13:40:42 -0500 Message-ID: Subject: Re: ob-python: import local package into a session To: Jack Kamm Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=tgbugs@gmail.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: Joost Kremers , Maxim Nikulin , emacs-orgmode 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=gmail.com header.s=20161025 header.b=oqjEeG8x; dmarc=pass (policy=none) header.from=gmail.com; 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.71 X-TUID: uVtuAeWBuKor I have also been dissatisfied with the current options for making local python libraries accessible in certain org files. The amount of setup that is required outside the org file itself was too large, especially if you want someone else who is not intimately familiar with python to be able to use it. My old solution was to modify the PYTHONPATH environment variable for the whole Emacs process. However, after a bit of digging inspired by this thread I now have a solution that is entirely local: advise ~org-babel-execute:python~ to set a new PYTHONPATH via the ~process-environment~ dynamic variable and set that from a buffer local variable for the local additions to PYTHONPATH along with getenv PYTHONPATH. A working example below. Best! Tom #+name: orgstrap #+begin_src elisp :results none :noweb noexport (defvar-local local-python-path nil) (defun advise--obe-python-path (command &rest args) (let ((process-environment (or (and local-python-path (cons (format "PYTHONPATH=%s" (concat local-python-path (getenv "PYTHONPATH"))) process-environment)) process-environment))) (apply command args))) (advice-add #'org-babel-execute:python :around #'advise--obe-python-path) (setq-local local-python-path (concat default-directory "code:")) #+end_src On Tue, Nov 24, 2020 at 9:26 AM Jack Kamm wrote: > > Joost Kremers writes: > > > I haven't really considered the option to install the utility functions as a > > package in the virtual environment, because I expect to change and develop those > > functions together with the rest of the project. If it were a separate package, > > I'd need to reinstall it every time I make changes to it, which will probably > > happen often. > > If you install the package using either "python setup.py develop", or > "pip install -e", then Python will install your code via symlinks > instead of copying, so then you don't have to worry about reinstalling > every time you make an edit. > > To switch between venv's in emacs, I use pyvenv: > https://github.com/jorgenschaefer/pyvenv >