From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: david larsson Newsgroups: gmane.lisp.guile.user Subject: Re: python-on-guile Date: Sun, 09 Feb 2020 20:39:48 +0100 Message-ID: References: <018d235b0c26bb87be28ddb1a2b26d42@selfhosted.xyz> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="38144"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Stefan Israelsson Tampe Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Feb 09 20:40:23 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j0sRJ-0009lg-8i for guile-user@m.gmane-mx.org; Sun, 09 Feb 2020 20:40:23 +0100 Original-Received: from localhost ([::1]:54004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0sRH-0003ow-So for guile-user@m.gmane-mx.org; Sun, 09 Feb 2020 14:40:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57958) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0sR6-0003oo-KX for guile-user@gnu.org; Sun, 09 Feb 2020 14:40:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j0sR5-0000vR-9Q for guile-user@gnu.org; Sun, 09 Feb 2020 14:40:08 -0500 Original-Received: from server0.selfhosted.xyz ([217.64.149.7]:58692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j0sR4-0000iV-Fi for guile-user@gnu.org; Sun, 09 Feb 2020 14:40:07 -0500 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=selfhosted.xyz; s=dkim; t=1581277200; bh=VSFtrpH35driIro8COKJNLkroDwdNCJYI9eHyHeu/Ns=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=I01NUh6fPfUqamc1MPYwD9n8YOkarnpY7/9gx5yU/OFI4/TaFxu52VvlcAt22CC5R SIFtNLXHXWzbfS+/vaVof+cwdNej49tIyk/92th5YJZN8yzg+nW5GWthvI8zp6jHaL zDhObDZABTsjnXY/T8bdmb/y5ApatdKnRYiiGF/Hgd3tRlHeaJCevl/AgeJhEhFaHf DeNeGBbhBhYohKWqKl3/wP/Fzy+verkYptlvfWJ3NZwqwdBdGEGCFtsDRFi1MecyKx R6jT6+9zyae4LugV1EnnebntVf2AI3IV2fvpnMyXTe6IbKCaC5163yg2+HOlqmSPQA frAPRPdpPcKyw== X-Fuglu-Suspect: ca945496e9274292af3c593836d83f24 X-Fuglu-Spamstatus: NO Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) In-Reply-To: X-Sender: david.larsson@selfhosted.xyz X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.64.149.7 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16147 Archived-At: Thanks for your explanations, but unfortunately I still can't figure out how to use this except in the simplest of cases. I am using the guix package python-on-guile 0.1.0-3.00a51a2 - maybe thats outdated? The simple things I have managed to do, are like: (add-to-load-path (dirname (current-filename))) (load-compiled python-test.go) where python-test.go is compiled with: guild compile python-test.py --output=python-test.go --from=python and contains simple things, like: f(s): a = s + 1 return a but if I add statements to python-test.py like: import netaddr def myfun(a) (netaddr is a module installed via: pip3 install --user netaddr) I receive an error about not finding the module. I am able to add only the modules which exist in the python-on-guile repo, like: import sys import base64 but Im getting errors, for example Im not able to use things from sys, like: sys.path.append() sys.path.insert(0, ) I was able to use some things from base64 but I only received weird results when converting between bytevectors and strings between the .scm file and .py file. What works fine using python3 python-test.py do not usually work when passing either a bytevector or string to the same go-compiled file from the .scm file using the python-code. Not sure whether there's a problem using python3 vs python2 here? Essentially, what Im looking for is how to proceed if I want to use modules installed via the pip package manager from guile, and what paths and imports I need to make, and how I might need to wrap them correctly in the scheme and python files to invoke a pip package procedure from guile. Best regards, David On 2020-02-09 18:59, Stefan Israelsson Tampe wrote: > I'm the author of that lib. > > 1) > > The main bindings are reachable through (language python module > python) > > So you could now go ahead and do >> (use-modules (language python module python)) >> ;L python > > And you will get a python shell that works quite ok for one liners > > 2) > > If you write a module and place it in a/b/c.py > you can use the classes and functions theirin by > > (use-modules (a b c)) > > 3) > you can load a .py file as (i hope this work) > (load "a.py") > > 4) > If you place a module in (language python module a.py) you can import > ir as a usual mode as >> from a import * > > The documentation is for the macro framework that enables you to work > with python classes and idioms like python iteration. > > Hope this helps > /Stefan > > On Sun, Feb 9, 2020 at 6:31 PM david larsson > wrote: > >> Hi everyone, >> I am trying to wrap my head around how to use the python-on-guile >> library, but Im struggling. Does anyone have example code that might >> >> help, and which isn't too advanced? >> >> All tips and suggestions appreciated! >> >> Best regards, >> David