# Communicating Python and Julia

**URL:** <https://discourse.julialang.org/t/communicating-python-and-julia/35455>\
**Category:** General Usage\
**Created:** [March 3, 2020, 11:10am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455 "2020-03-03T11:10:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eldho.Ashna](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Eldho.Ashna](https://discourse.julialang.org/u/Eldho.Ashna)\
**Post date:** [March 3, 2020, 11:10am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/1 "2020-03-03T11:10:24Z")

</div>

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: [https://github.com/JuliaPy/PyCall.jl](https://github.com/JuliaPy/PyCall.jl) , [https://github.com/JuliaCN/Py2Jl.jl](https://github.com/JuliaCN/Py2Jl.jl) and [https://github.com/JuliaPy/pyjulia](https://github.com/JuliaPy/pyjulia). 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.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [March 3, 2020, 11:20am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/2 "2020-03-03T11:20:33Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Eldho.Ashna](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Eldho.Ashna](https://discourse.julialang.org/u/Eldho.Ashna)\
**Post date:** [March 3, 2020, 11:36am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/3 "2020-03-03T11:36:10Z")

</div>

I want to call python from julia

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [March 3, 2020, 11:38am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/4 "2020-03-03T11:38:40Z")

</div>

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

```julia
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](https://github.com/JuliaPy/PyCall.jl).

---

<div class="post-metadata">

**Author:** ![Eldho.Ashna](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Eldho.Ashna](https://discourse.julialang.org/u/Eldho.Ashna)\
**Post date:** [March 3, 2020, 11:43am UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/5 "2020-03-03T11:43:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 3, 2020, 12:27pm UTC](https://discourse.julialang.org/t/communicating-python-and-julia/35455/6 "2020-03-03T12:27:59Z")

</div>

> [@Eldho.Ashna](#):
>
> 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).

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.
