{"id":9852,"library":"juliacall","title":"juliacall","description":"juliacall is a Python library that enables seamless interoperability between Python and Julia, allowing Python code to call Julia functions, access Julia variables, and evaluate Julia code. It's part of the broader PythonCall.jl project which provides bidirectional integration. The library is actively maintained with frequent updates, often several minor releases per month.","status":"active","version":"0.9.31","language":"en","source_language":"en","source_url":"https://github.com/JuliaPy/PythonCall.jl","tags":["julia","interoperability","data science","scientific computing"],"install":[{"cmd":"pip install juliacall","lang":"bash","label":"Install juliacall"}],"dependencies":[],"imports":[{"note":"Instantiates a new, isolated Julia session.","symbol":"Julia","correct":"from juliacall import Julia"},{"note":"Provides access to the main module of the current Julia session.","symbol":"Main","correct":"from juliacall import Main"}],"quickstart":{"code":"from juliacall import Julia\nimport os\n\n# For robust demos, ensure Julia is found (optional, but good practice if not on PATH)\n# os.environ['JULIA_BIN'] = '/path/to/your/julia/bin/julia' # Uncomment and modify if needed\n\ntry:\n    jl = Julia() # Initializes a Julia session\n    \n    # Evaluate Julia code\n    jl.seval(\"x = 10; y = 20\")\n    print(f\"Julia variable x: {jl.x}\")\n    print(f\"Julia variable y: {jl.y}\")\n    \n    # Call a Julia function\n    result = jl.cos(jl.pi) # Access Julia's pi and cos function\n    print(f\"cos(pi) from Julia: {result}\")\n\n    # Define and call a custom Julia function\n    jl.seval(\"my_add(a, b) = a + b\")\n    custom_result = jl.my_add(5, 7)\n    print(f\"Custom Julia function my_add(5, 7): {custom_result}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure Julia is installed and discoverable (e.g., on PATH or via JULIA_BIN env var).\")","lang":"python","description":"This quickstart demonstrates how to initialize a Julia session, evaluate Julia code, access Julia variables, and call both built-in and custom Julia functions from Python using juliacall."},"warnings":[{"fix":"Install Julia from https://julialang.org/downloads/. Ensure Julia's `bin` directory is on your system's PATH, or set the `JULIA_BIN` environment variable to the full path of the Julia executable (e.g., `/usr/local/julia-1.8.5/bin/julia`).","message":"juliacall requires a separate Julia installation on your system. It is not automatically installed via pip and will not function without a correctly configured Julia runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For global state or reusing an existing Julia session, import `Main` instead of `Julia`: `from juliacall import Main; jl = Main`. If you need isolated environments, instantiate `Julia()` once and reuse the object.","message":"Instantiating `juliacall.Julia()` creates a new, isolated Julia session, which can be slow and memory-intensive upon first call. For accessing an existing Julia environment or global state, `juliacall.Main` is often more appropriate and performs better after the initial load.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the `juliacall` documentation on type conversion to understand the mappings. For critical performance or complex data, consider explicit type hints or using data structures that convert predictably, like NumPy arrays (which map to Julia arrays).","message":"Automatic type conversions between Python and Julia can sometimes lead to unexpected behavior or performance overhead, especially for complex or mutable data structures. For example, Python lists might convert to Julia `Vector{Any}` which can be less performant than a specific `Vector{Int}`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install Julia from https://julialang.org/downloads/. Add Julia's `bin` directory to your system's PATH, or set the `JULIA_BIN` environment variable to the full path of the Julia executable (e.g., `export JULIA_BIN=/opt/julia-1.9.3/bin/julia`).","cause":"The juliacall library could not locate the Julia executable on your system.","error":"JuliaError: Couldn't find Julia. Ensure Julia is installed and on your PATH, or set the JULIA_BIN environment variable."},{"fix":"Run `pip install juliacall` in your terminal to install the package.","cause":"The juliacall Python package is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'juliacall'"},{"fix":"Ensure the Julia code defining `my_julia_function` (e.g., via `jl.seval(\"my_julia_function(x) = x^2\")`) has been executed *before* attempting to call it. Remember that `Julia()` instances are isolated, while `Main` shares the global Julia environment.","cause":"The Julia function or variable you are trying to access has not been defined in the current Julia session or is not in the scope of the `Julia` or `Main` object you are using.","error":"AttributeError: 'Julia' object has no attribute 'my_julia_function'"}]}