Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

419
Vistas
I have a high-performant function written in Julia, how can I use it from Python?

I have a found a Julia function that nicely does the job I need. How can I quickly integrate it to be able to call it from Python?

Suppose the function is

f(x,y) = 2x.+y

What is the best and most elegent way to use it from Python?

over 4 years ago · Hanz Gallego
1 Respuestas
Responde la pregunta

0

Assuming your Python and Julia are installed you need to take the following steps.

  1. Run Julia and install PyCall

    using Pkg
    pkg"add PyCall"
    
  2. Put your code into a Julia package

    using Pkg
    Pkg.generate("MyPackage")
    

    In the folder src you will find MyPackage.jl, edit it to look like this:

    module MyPackage
    f(x,y) = 2x.+y
    export f
    end
    
  3. Install pyjulia

    python -m pip install julia
    

    (On Linux systems you might want to use python3 instead of python command)

    For this step note that while an external Python can be used with Julia. However, for a convenience it might be worth to consider using a Python that got installed together with Julia as PyCall. In that case for installation use a command such this one:

    %HOMEPATH%\.julia\conda\3\python -m pip install julia
    

    or on Linux

    ~/.julia/conda/3/python -m pip install julia
    

    Note that if you have JULIA_DEPOT_PATH variable defined you can replace %HOMEPATH%\.julia or ~/.julia/ with its value.

  4. Run the appropiate Python and tell it to configure the Python-Julia integration:

    import julia
    julia.install()
    
  5. Now you are ready to call your Julia code:

    >>> from julia import Pkg
    >>> Pkg.activate(".\\MyPackage") #use the correct path
        Activating environment at `MyPackage\Project.toml`
    >>> from julia import MyPackage
    >>> MyPackage.f([1,2],5)
        [7,9]
    

It is worth noting that the proposed approach in this answer has several advantages over a standalone Julia file which would be possible, although is less recommended. The advantages include:

  1. Packages get precompiled (so they are faster in subsequent runs) and can be loaded as a package in Python.
  2. Packages come with their own virtual environment via 1Project.toml` which makes production deployments much comfortable.
  3. A Julia package can be statically compiled into Julia's system image which can slash itsloading time --- see https://github.com/JuliaLang/PackageCompiler.jl .
over 4 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda