# Python project calling Julia functions

**URL:** <https://discourse.julialang.org/t/python-project-calling-julia-functions/116191>\
**Category:** General Usage\
**Tags:** question, package, pythoncall\
**Created:** [June 25, 2024, 9:04am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191 "2024-06-25T09:04:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 25, 2024, 9:04am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191/1 "2024-06-25T09:04:02Z")

</div>

I need to create a Python project that calls some of the functions exported by my Julia package `KiteModels.jl`. I need to manage both the Python and the Julia dependencies.

What would be a good way to do that?

For now it only needs to work on Ubuntu, but a more general solution would of course also be nice.

---

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [July 2, 2024, 6:04am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191/2 "2024-07-02T06:04:12Z")

</div>

For the projects where I have to use python I mostly use PythonCall.jl.  
For managing Julia and Python dependencies it is probably the best solution.

It will generate a CondaProject.toml file that keeps track of your packages and uses micromamba to install python and the respective packages and comes with a package manager for python that can be addressed from the REPL by prefixing the normal package mananger with `conda`. So

```julia
pkg > conda add scikit-learn

```

will do everything for you that you’d expect.

Note, if you want to use an external python installation with existing environments, make sure to set the paths correctly, as explained in the manual, before you do

```julia
julia> using PythonCall
pkg> conda add ...

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 2, 2024, 6:37am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191/3 "2024-07-02T06:37:29Z")

</div>

The package actually implementing the underlying conda functionality is CondaPkg.jl:

> **[GitHub - JuliaPy/CondaPkg.jl: Add Conda dependencies to your Julia project](https://github.com/JuliaPy/CondaPkg.jl)**
>
> Add Conda dependencies to your Julia project. Contribute to JuliaPy/CondaPkg.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 2, 2024, 7:14am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191/4 "2024-07-02T07:14:24Z")

</div>

Well, this is not what I need. There is a partner company, they have their own Python Software which is closed source and their own way to install it. They want to use my Kite power system model, mainly two functions, init() and step().

I am writing an example how to use my Julia SW from Python.

For now I am using [pixi](https://pixi.sh/latest/) to install Python and juliaup to install Julia. When I find the time I will publish the example code on Github.

Example how to create a Python project with juliacall:

```julia
pixi init new_project
cd new_project
pixi add python==3.8.19
pixi add juliacall --pypi
pixi add ipython
pixi add numpy

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 2, 2024, 7:16am UTC](https://discourse.julialang.org/t/python-project-calling-julia-functions/116191/5 "2024-07-02T07:16:35Z")

</div>

So you need juliacall then:

> **[Guide · PythonCall & JuliaCall](https://juliapy.github.io/PythonCall.jl/stable/juliacall/)**
>
> Documentation for PythonCall & JuliaCall.

I have juliacall available on conda-forge as `pyjuliacall`:

> [@\[ANN\] pyjuliacall and pyjuliapkg packaged on conda-forge](https://discourse.julialang.org/t/ann-pyjuliacall-and-pyjuliapkg-packaged-on-conda-forge/109849):
>
> juliacall and juliapkg on conda-forge I am happy to announce that the Python packages juliacall and juliapkg by @cjdoris have been packaged for conda-forge as [pyjuliacall](https://anaconda.org/conda-forge/pyjuliacall) and [pyjuliapkg](https://anaconda.org/conda-forge/pyjuliapkg). Why add the “py” prefix? In principle, conda-forge is a language agnostic package ecosystem. Since there is also a [juliacall package for R on CRAN](https://cran.r-project.org/web/packages/JuliaCall/index.html), the py prefix was added to disambiguate the Python package from the similarly named R package. Using conda to install juliacall and juliapkg pyjuliapkg is a depend…

You can thus use pixi to install pyjuliacall. Alternately, you could just do `pip install juliacall`
