|
| 1 | +Troubleshooting |
| 2 | +--------------- |
| 3 | + |
| 4 | +### Your Python interpreter is statically linked to libpython |
| 5 | + |
| 6 | +If you use Python installed with Debian-based Linux distribution such |
| 7 | +as Ubuntu or install Python by `conda`, you might have noticed that |
| 8 | +PyJulia cannot be initialized properly with Julia ≥ 0.7. This is |
| 9 | +because those Python executables are statically linked to libpython. |
| 10 | +(See [Limitations](limitations.md) for why that's a problem.) |
| 11 | + |
| 12 | +If you are unsure if your `python` has this problem, you can quickly |
| 13 | +check it by: |
| 14 | + |
| 15 | +```console |
| 16 | +$ ldd /usr/bin/python |
| 17 | + linux-vdso.so.1 (0x00007ffd73f7c000) |
| 18 | + libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f10ef84e000) |
| 19 | + libc.so.6 => /usr/lib/libc.so.6 (0x00007f10ef68a000) |
| 20 | + libpython3.7m.so.1.0 => /usr/lib/libpython3.7m.so.1.0 (0x00007f10ef116000) |
| 21 | + /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f10efaa4000) |
| 22 | + libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f10ef111000) |
| 23 | + libutil.so.1 => /usr/lib/libutil.so.1 (0x00007f10ef10c000) |
| 24 | + libm.so.6 => /usr/lib/libm.so.6 (0x00007f10eef87000) |
| 25 | +``` |
| 26 | + |
| 27 | +in Linux where `/usr/bin/python` should be replaced with the path to |
| 28 | +your `python` command (use `which python` to find it out). In macOS, |
| 29 | +use `otool -L` instead of `ldd`. If it does not print the path to |
| 30 | +libpython like `/usr/lib/libpython3.7m.so.1.0` in above example, you |
| 31 | +need to use one of the workaround below. |
| 32 | + |
| 33 | +The easiest workaround is to use the `python-jl` command bundled in |
| 34 | +PyJulia. This can be used instead of normal `python` command for |
| 35 | +basic use-cases such as: |
| 36 | + |
| 37 | +```console |
| 38 | +$ python-jl your_script.py |
| 39 | +$ python-jl -c 'from julia.Base import banner; banner()' |
| 40 | +$ python-jl -m IPython |
| 41 | +``` |
| 42 | + |
| 43 | +See `python-jl --help` for more information. |
| 44 | + |
| 45 | +Note that `python-jl` works by launching Python interpreter inside |
| 46 | +Julia. Importantly, it means that PyJulia has to be installed in the |
| 47 | +Python environment with which PyCall is configured. That is to say, |
| 48 | +following commands must work for `python-jl` to be usable: |
| 49 | + |
| 50 | +```julia |
| 51 | +julia> using PyCall |
| 52 | + |
| 53 | +julia> pyimport("julia") |
| 54 | +PyObject <module 'julia' from '/.../julia/__init__.py'> |
| 55 | +``` |
| 56 | + |
| 57 | +In fact, you can simply use PyJulia inside the Julia REPL, if you are |
| 58 | +comfortable with working in it: |
| 59 | + |
| 60 | +```julia |
| 61 | +julia> using PyCall |
| 62 | + |
| 63 | +julia> py""" |
| 64 | + from julia import Julia |
| 65 | + Julia(init_julia=False) |
| 66 | +
|
| 67 | + from your_module_using_pyjulia import function |
| 68 | + function() |
| 69 | + """ |
| 70 | +``` |
| 71 | + |
| 72 | +Alternatively, you can use [pyenv](https://github.com/pyenv/pyenv) to |
| 73 | +build Python with |
| 74 | +[`--enable-shared` option](https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with---enable-shared). |
| 75 | +Of course, manually building from Python source distribution with the |
| 76 | +same configuration also works. |
| 77 | + |
| 78 | +```console |
| 79 | +$ PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.6 |
| 80 | +Downloading Python-3.6.6.tar.xz... |
| 81 | +-> https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz |
| 82 | +Installing Python-3.6.6... |
| 83 | +Installed Python-3.6.6 to /home/USER/.pyenv/versions/3.6.6 |
| 84 | + |
| 85 | +$ ldd ~/.pyenv/versions/3.6.6/bin/python3.6 | grep libpython |
| 86 | + libpython3.6m.so.1.0 => /home/USER/.pyenv/versions/3.6.6/lib/libpython3.6m.so.1.0 (0x00007fca44c8b000) |
| 87 | +``` |
| 88 | + |
| 89 | +For more discussion, see: |
| 90 | +https://github.com/JuliaPy/pyjulia/issues/185 |
| 91 | + |
| 92 | +### Segmentation fault in IPython |
| 93 | + |
| 94 | +You may experience segmentation fault when using PyJulia in old |
| 95 | +versions of IPython. You can avoid this issue by updating IPython to |
| 96 | +7.0 or above. Alternatively, you can use IPython via Jupyter (e.g., |
| 97 | +`jupyter console`) to workaround the problem. |
| 98 | + |
| 99 | +### Error due to `libstdc++` version |
| 100 | + |
| 101 | +When you use PyJulia with another Python extension, you may see an |
| 102 | +error like ``version `GLIBCXX_3.4.22' not found`` (Linux) or `The |
| 103 | +procedure entry point ... could not be located in the dynamic link |
| 104 | +library libstdc++6.dll` (Windows). In this case, you might have |
| 105 | +observed that initializing PyJulia first fixes the problem. This is |
| 106 | +because Julia (or likely its dependencies like LLVM) requires a recent |
| 107 | +version of `libstdc++`. |
| 108 | + |
| 109 | +Possible fixes: |
| 110 | + |
| 111 | +* Initialize PyJulia (e.g., by `from julia import Main`) as early as |
| 112 | + possible. Note that just importing PyJulia (`import julia`) does |
| 113 | + not work. |
| 114 | +* Load `libstdc++.so.6` first by setting environment variable |
| 115 | + `LD_PRELOAD` (Linux) to |
| 116 | + `/PATH/TO/JULIA/DIR/lib/julia/libstdc++.so.6` where |
| 117 | + `/PATH/TO/JULIA/DIR/lib` is the directory which has `libjulia.so`. |
| 118 | + macOS and Windows likely to have similar mechanisms (untested). |
| 119 | +* Similarly, set environment variable `LD_LIBRARY_PATH` (Linux) to |
| 120 | + `/PATH/TO/JULIA/DIR/lib/julia` directory. Using `DYLD_LIBRARY_PATH` |
| 121 | + on macOS and `PATH` on Windows may work (untested). |
| 122 | + |
| 123 | +See: |
| 124 | +https://github.com/JuliaPy/pyjulia/issues/180, |
| 125 | +https://github.com/JuliaPy/pyjulia/issues/223 |
0 commit comments