`using Pycall` on Google Colab makes Julia runtime crash

I’d like to use PyCall on Google Colab Julia runtime, but not succeeded.

import Pkg; Pkg.add("PyCall") works, however, using PyCall would crash.

run(which python) shows /usr/local/bin/python, run(which pip) shows /usr/local/bin/pip.

Log:

using PyCall
[4775] signal 11 (1): Segmentation fault
in expression starting at none:1
PyObject_GC_Del at /usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0 (unknown line)
unknown function (ip: 0x7b351392224c)
pydecref_ at /root/.julia/packages/PyCall/1gn3u/src/PyCall.jl:118
pydecref at /root/.julia/packages/PyCall/1gn3u/src/PyCall.jl:123
jfptr_pydecref_4467 at /root/.julia/compiled/v1.11/PyCall/GkzkC_0abgj.so (unknown line)
run_finalizer at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gc.c:303
jl_gc_run_finalizers_in_list at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gc.c:393
run_finalizers at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gc.c:439
jl_mutex_unlock at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/julia_locks.h:80 [inlined]
jl_generate_fptr_impl at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/jitlayers.cpp:545
jl_compile_method_internal at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gf.c:2536 [inlined]
jl_compile_method_internal at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gf.c:2423
ijl_compile_method_instance at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gf.c:2860
ijl_compile_hint at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/gf.c:2873

I also tried below, but nothing fixed.

ENV["PYTHON"] = "/usr/local/bin/python"
import Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")
1 Like

Either use PythonCall.jl , or start Julia single threaded:

julia -t 1,0

Thank you! PythonCall is working now. I’ll try Julia single threaded also :slight_smile:

1 Like

Solved. Not using default Julia runtime, but creating custom runtime with single threaded solved this problem. Now PyCall worked. Thank you very much!!

julia-jupyter-install.ipynb:

{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "julia-jupyter-install.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "julia-1.11",
      "display_name": "julia-1.11"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "CN08w8uiICa8",
        "colab_type": "code",
        "colab": {}
      },

      "source": [
        "#!curl -sSL \"https://julialang-s3.julialang.org/bin/linux/x64/1.11/julia-1.11.5-linux-x86_64.tar.gz\" -o julia.tar.gz\n",
        "#!tar -xzf julia.tar.gz -C /usr --strip-components 1\n",
        "#!rm -rf julia.tar.gz*\n",
        "!julia -e 'using Pkg; Pkg.add(\"IJulia\")'\n",
        "!echo \"Installing IJulia kernel...\"\n",
        "!julia -e 'using IJulia; IJulia.installkernel(\"julia\", env=Dict(\"JULIA_NUM_THREADS\"=>\"1\"))'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sGOaN98-IZxj",
        "colab_type": "text"
      },
      "source": [
        "After executing the above with Shift+Enter, click \"Runtime\" > \"Change Runtime Type\" > \"Save.\" and restart runtime."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ls5Cl0hsIndc",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "versioninfo()"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}