[SciPy-User] calling Julia module from Python?

Geordie McBain gdmcbain at freeshell.org
Sun May 17 21:21:47 EDT 2015


2015-05-16 2:47 GMT+10:00 asreeve <asreeve at maine.edu>:
> I would like some guidance in using the Julia Language (v:0.3.8) from
> Python(v:3.4.3), to see if it can be used for creating fast modules
> for Python scripts.
>
> I've written a short function in Julia and would like to call it from
> a python script. To get started, I'm trying to load the Julia script
> into an ipython shell. I can call the module from Julia, and can
> execute short bits of Julia in the ipython shell.
>
> Here's where I'm at now (the Julia module I'm calling is at the end of
> this message):
>
> Using Julia
> ===========
>
> julia> using snow_frac2
>
> julia> snow_frac2.snow_fraction2(1.)
> 0.5
> ===========
>
> Using Python
> ============
>
> In [1]: import julia
>
> In [2]: jl=julia.Julia()
>
> In [3]: jl.eval('sin(3.14)')
> Out[3]: 0.0015926529164868282
>
> ===========
>
> I'd like to call the "snow_frac2.jl" module below from the ipython
> interpreter, just like I did in in Julia, and use the snow_fraction2
> function. I've attempted a variety of commands
> (eg. foo=jl.call('snow_frac2.jl')) but just get "JuliaError"s. Can
> anyone show the proper incantation to call a Julia module from Python?
> I've tried updating to a more recent verion of Julia, but that did not
> seem to help (although I gave up on this pretty quickly).

Hello.  There was a thread about Julia last month

  http://mail.scipy.org/pipermail/scipy-user/2015-April/036450.html

referring to

  http://blog.leahhanson.us/julia-calling-python-calling-julia.html

Based on that, it looks like what's needed is:

%<---
import julia

j = julia.Julia()
j.eval('using snow_frac2')
print(j.eval('snow_frac2.snow_fraction2(1.)'))
--->%

This works here.

$ python snow_frac2.py
0.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snow_frac2.py
Type: text/x-python
Size: 107 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150518/eb604400/attachment.py>


More information about the SciPy-User mailing list