Wrap Julia package in Python: which is the best option?

I have written some modules in Julia that I’d like to call from Python.
While this is not an issue per se, I’d like to be able to call those packages without having Julia installed. Although this may look as a weird request, I want to share my codes with other people I am working with…that mainly works with Python.

After a quick discussion with @miguelraz , I have considered several options:

  1. Using JuliaCall . From the description, it looks that it could handle automatically the installation of Julia if no local version is found.
  2. Make a Python wrapper, such as in diffeqpy (@miguelraz suggested me to tag @ChrisRackauckas )
  3. Make a Python wrapper, such as in @MilesCranmer 's PySr. If I correctly understand, the conda forge recipy automatically installs Julia if required.

I know that installing Julia is not difficult, but I’d like to make at least a module that is pip installable and does not require manual Julia installation, to start spreading Julia with older peeps in my group.

I thank you in advance for your suggestions.


I would like @tkf to help with getting Use julia_project to manage Julia dependency by jlapeyre · Pull Request #100 · SciML/diffeqpy · GitHub finished, as that would probably be the “best” way in some sense of “best”. Right now we’re in a few decent but only okay local optima.

1 Like

I also don’t know what the best solution is, but I’ll share my experience:

I’ve had a really good overall experience using conda-forge to manage the installation of PySR–which is itself a scikit-learn Python frontend to SymbolicRegression.jl.

Users of the package–many of whom have never even heard of Julia–don’t need to worry about ever touching Julia themselves; everything (Julia binary + PyJulia) is installed automatically by conda. Since conda installs a full-blown version of Julia, to update/install packages I call Pkg normally from inside PySR and have an environment installed which is specific to the version of the package. For example, PySR v0.7.9 would have its julia deps under a shared environment @pysr-0.7.9 within conda’s Julia registry–PySR itself creates this environment upon running pysr.install().

The Julia “feedstock” is well-maintained (thanks to the hard work of @mkitti and @ngam!), and to create my package I only need to list Julia and PyJulia as dependencies in this build file. You would submit a file like this to the conda-forge repo and they generate your feedstock repo automatically.

Now, the major downside of this is that you need to use conda which is very heavyweight (although it is nice to have a nearly hermetic environment despite using two separate languages!). In practice I actually have both conda and pip setup, and just let the user decide whether they want to install Julia manually for pip, or just conda.