Communicating Python and Julia

Hi everyone.

For converting python code to C, we have Cython. Similarly, there is no such package to convert python to Julia(correct me if I’m wrong). Thus, I want my python code to communicate with Julia. I came through 3 links: , and I’m not understanding any of these links. What is the difference between these?

Can someone explain me in simple steps how to make python code communicate with Julia.

Thanking you in advance.

Which direction do you want to communicate? Do you want to call

  • Python from Julia -> PyCall.jl
  • Julia from Python -> pyjulia

I’m not sure how you think Cython features in this…

1 Like

I want to call python from julia

Here an example for how to use numpy’s eigensolver to diagonalize a Julia matrix:

julia> using PyCall

julia> np = pyimport("numpy");

julia> np.linalg.eig(rand(2,2))
([0.6985193636313655, -0.05970543416154339], [0.8873181722592743 -0.26035921669421536; 0.4611577400179475 0.965511821927818])

For more, see PyCall.jl.


I have one doubt. I have trained my neural networks using keras and tensorflow in python. Now, I’m writing a main program in Julia to call this. My doubt is- will this work if the weight file obtained is by training in python,i.e, will julia main program be able to call my weight files(trained using python).

Also, will this communication work as I have used OpenCV, keras, tensorflow etc.

PyCall can in principle call any Python code, because it links to libpython and lets Python execute natively. It even supports bidirectional code calling (Julia and Python functions can both call one another).

Of course, sometimes there are hiccups and you need to read the documentation and understand some things. For example, you occasionally need to be explicit about how/whether you want to convert Python datatypes to Julia or vice versa. And there are occasionally conflicts between shared libraries used by Python and Julia that require care in how Julia is compiles.