No.
However it is safe to use PythonCall with Julia with multiple threads, provided you only call Python code from the first thread. (Before v0.9.22, tricks such as disabling the garbage collector were required.)
From Python, to use JuliaCall with multiple threads you probably need to set
[PYTHON_JULIACALL_HANDLE_SIGNALS=yes
](@ref julia-config) before importing JuliaCall.
This is because Julia intentionally causes segmentation faults as part of the GC
safepoint mechanism. If unhandled, these segfaults will result in termination of the
process. This is equivalent to starting julia with julia --handle-signals=yes
, the
default behavior in Julia. See discussion
here
for more information.
Related issues: #201, #202, #529
When a Julia array is passed to Python, it is wrapped as a ArrayValue
.
This type satisfies the Numpy array interface and the buffer protocol, so can be used in
most places where a numpy array is valid.
However, some Python packages have functions which assume the input is an actual Numpy array. You may see errors such as:
AttributeError: Julia: type Array has no field dtype
To fix this you can convert the array x
to a Numpy array as follows
Py(x).to_numpy()
If the array is being mutated, you will need to pass the argument copy=false
.
Related issues: #280
On some systems, you may see an error like the following when using torch
and juliacall
:
Python(65251,0x104cf8580) malloc: Heap corruption detected, free list is damaged at 0x600001c17280
*** Incorrect guard value: 1903002876
Python(65251,0x104cf8580) malloc: *** set a breakpoint in malloc_error_break to debug
[1] 65251 abort ipython
A solution is to ensure that juliacall
is imported before torch
.
Related issues: #215
On some systems, you may see an error like the following when import e.g. matplotlib
before juliacall
:
ERROR: `ccall` requires the compilerTraceback (most recent call last):
File "/home/dingraha/projects/pythoncall_import_error/run.py", line 2, in <module>
from foo import Foo
File "/home/dingraha/projects/pythoncall_import_error/foo.py", line 4, in <module>
import juliacall; jl = juliacall.newmodule("FooModule")
File "/home/dingraha/projects/pythoncall_import_error/venv/lib/python3.9/site-packages/juliacall/__init__.py", line 218, in <module>
init()
File "/home/dingraha/projects/pythoncall_import_error/venv/lib/python3.9/site-packages/juliacall/__init__.py", line 214, in init
raise Exception('PythonCall.jl did not start properly')
Exception: PythonCall.jl did not start properly
The likely problem is that the "other" Python library (matplotlib
, whatever) is loading the system libstdc++.so
, which isn't compatible with the libstdc++.so
that Julia ships with.
Linux distributions with older libstdc++
versions seem more likely to suffer from this issue.
The solution is to either:
- use a Linux distribution with a more recent
libstdc++
- import
juliacall
before the other Python library, so that Julia'slibstdc++
is loaded - use a Python from a conda environment, which will have a newer
libstdc++
that is compatible with Julia's
Related issues: #255
Yes, it may be possible. A good example of that is having Julia running inside the Python that is running inside Blender, as presented in this Discourse post. From the point that one has JuliaCall running inside Python, if it has access to the terminal, one can even launch a Julia REPL there, and if needed connect with VSCode Julia extension to it. The full Python script to install, launch JuliaCall, and launch a Julia REPL in Blender is here.