Calling Julia from Python

844 views
Skip to first unread message

Hans W Borchers

unread,
Aug 31, 2014, 8:22:41 AM8/31/14
to julia...@googlegroups.com
I will give a talk on Julia in front of a group of Python users. The
presentation will make use of IJulia and the IPython notebook, and everything
works really nice, including calling Python from Julia.

To make it even relevant for Python people I would like to show how to call
Julia from Python. So I installed the "julia" Python package within IJulia:

    cd ~/.julia/v0.3/IJulia/python
    sudo python setup.py install

After that, when calling Julia I get

    >>> from julia import Julia
    >>> j = Julia()
    ...
    ValueError: Julia release library not found
      searched /usr/lib/libjulia.so
       and /usr/lib/libjulia.dylib

I can correct this in file ".../site-packages/julia/core.py" manually to find
this library at "/usr/lib/x86_64-linux-gnu/julia/libjulia.so":

    >>> from julia import Julia
    >>> j = Julia()
    System image file "/usr/bin/../lib/julia/sys.ji" not found

and here, I apologize, I gave up.
(I tried the pyjulia Python package, too, but was not more successful.)

I am ready to install everything anew, Python, Julia, ..., but I have no idea
what to do differently this time.

[Versioninfo: Ubuntu Linux 14.04, Python 2.7.6, Julia 0.3.0 latest]

Steven G. Johnson

unread,
Aug 31, 2014, 8:42:56 AM8/31/14
to julia...@googlegroups.com
It works for me on my Mac. Can you file a pyjulia issue?

Hans W Borchers

unread,
Sep 1, 2014, 5:48:02 AM9/1/14
to julia...@googlegroups.com
Think I will wait for one or two days. Maybe someone on Ubuntu or Linux Mint
has a tip. Changing to LM would not be a problem at all. Your reply reinforced
my wish to "go back to the Mac".

Jake Bolewski

unread,
Sep 1, 2014, 2:33:35 PM9/1/14
to julia...@googlegroups.com
Hi Hans,

This should be fixed on master.  I'm still working on unicode issues.  Getting unicode to work between python2 / python3 is kind of a pain.

Best,
Jake

Hans W Borchers

unread,
Sep 1, 2014, 2:47:18 PM9/1/14
to julia...@googlegroups.com
Jake, which muster do you mean -- what would I need to reinstall?

Steven G. Johnson

unread,
Sep 1, 2014, 4:08:16 PM9/1/14
to julia...@googlegroups.com


On Monday, September 1, 2014 2:47:18 PM UTC-4, Hans W Borchers wrote:
Jake, which muster do you mean -- what would I need to reinstall?

He means pyjulia master (do a 'git pull origin master' in the pyjulia directory).

Hans W Borchers

unread,
Sep 1, 2014, 5:02:37 PM9/1/14
to julia...@googlegroups.com
Thanks a lot for this prompt reaction.
I can now import 'julia' into Python, but I don't seem to get the right results:

    >>> from julia import Julia
    >>> j = Julia()

    >>> j.eval('PyObject((1,2,3))')     # works fine!
    (1, 2, 3)

    >>> j.call('1+1')                   # what is this ...
    23296656

    >>> j.call('sqrt(2.0)')             # ... and this?
    173117264

    >>> j.run('1+1')                    # shouldn't this work?
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    RuntimeError: Julia exception: MethodError(run,("1+1",))

I am sorry I bother everybody here. Maybe my installation is too 'kaputt' by now.

Jake Bolewski

unread,
Sep 1, 2014, 5:32:06 PM9/1/14
to julia...@googlegroups.com
To execute arbitrary julia code it is "eval" just like python, call returns a void pointer to the result.

examples:

import julia
julia = julia.Julia()
julia.eval("1 +1")
julia.sqrt(2.0)
julia.help("sqrt") # get the help for julia's sqrt function

from julia import Pkg # or any user installed package on your system
Pkg.installed()
Pkg.#ipython tab expansion should work for any package

from julia import randn as r # should be able to import just as you would in python
r(100)

etc...

etc...

Hans W Borchers

unread,
Sep 1, 2014, 6:41:48 PM9/1/14
to julia...@googlegroups.com
Jake, thanks, it now works as you say; very nice.

I was referring to the examples in Leah Hanson's blog entry

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

which appear to be out-of-date. It would be helpful to have some
of your examples in the README file of the 'pyjulia' package.

Jake Bolewski

unread,
Sep 1, 2014, 9:31:35 PM9/1/14
to julia...@googlegroups.com
Hi Hans,

Glad you got it working, I'll add some examples to README.   Right now pyjulia is demoware, cool to show off than you can do it but still just a toy.  Supporting python 3.4 looks like it is going to be a pain as the whole meta-import machinery changed.  Best to use python 2.7 and avoid unicode for the time being :-)

Hope your presentation goes well,
Jake
Reply all
Reply to author
Forward
0 new messages