Using Python libraries in Racket
<p>Can I use Python code and libraries in Racket?  I have installed PyonR (<a href="https://github.com/pedropramos/PyonR" rel="nofollow">https://github.com/pedropramos/PyonR</a>) in DrRacket so I can choose "#lang python" and run Python code. But how can I combine Racket and Python language codes for my application?</p>

<p>There is also a limited Python to Lisp translator at <a href="https://github.com/nurv/pnil" rel="nofollow">https://github.com/nurv/pnil</a> . Is there something similar for Racket?</p>

<hr>

<p>Edit: As advised in comments, I tried following. This python code in file "pysamples.rkt" works well in DrRacket: </p>

<pre><code>#lang python

def greet(name):
    print 'Hello', name

greet('Alfred')
</code></pre>

<p>Output: </p>

<pre><code>Hello Alfred
</code></pre>

<p>I tried using above definition in Racket code, but it did not work. Following is the Racket code: </p>

<pre><code>#lang racket
; (require python/config) (enable-cpyimport!) ; ran this once; worked.

(#%require "pysamples.rkt")
(greet "Racket_code")
</code></pre>

<p>The error is: </p>

<pre><code>greet: unbound identifier in module in: greet
</code></pre>

<p><a href="https://github.com/pedropramos/PyonR" rel="nofollow">Accoring to the readme</a> you can import python 2.7 packages, but you need to use <code>cpyimport</code>. One of the examples looks like this:</p>

<pre><code>#lang python
cpyimport numpy as np
from "racket" import time

    def add_arrays(n):
        result = np.zeros((100,100))
        for i in range(n):
            result += np.random.randint(0, 100000, (100,100))
        return result

    print time(add_arrays(10000))
</code></pre>

<p>Looking at the code, a pure python library you could just import give that it's in rackets paths and was given <code>#lang python</code> top line. all defined are always exported.</p>

python racket ffi