# install JuliaCall within Blender's Python environment (if not already installed)
import importlib
if importlib.util.find_spec('juliacall') is None:
import pip
pip.main(['install', 'juliacall'])
# set number of Julia threads to 1 (otherwise bpy usage will crash)
import os
os.environ["PYTHON_JULIACALL_THREADS"] = "1"
# load Julia with JuliaCall
import juliacall
# start Julia REPL in the terminal
juliacall.Main.seval('import REPL; import Pkg; Base.active_repl = REPL.LineEditREPL(REPL.Terminals.TTYTerminal(get(ENV,"TERM",""),stdin,stdout,stderr), true); Threads.@spawn :interactive REPL.run_repl(Base.active_repl, backend->(Base.active_repl_backend = backend));')
# load PythonCall and bpy Python module within Julia
juliacall.Main.seval('using PythonCall; bpy = pyimport("bpy")')
# schedule a Blender timer to allow Julia run
import bpy
def julia_work():
juliacall.Main.sleep(0.01)
return 0.01
julia_timer = bpy.app.timers.register(julia_work, persistent=True)
(the first run may take a while to install JuliaCall)
After that, we have a Julia REPL in the terminal where Blender is running. Additionally, we can connect to the VSCode Julia extension with its Julia: Connect external REPL
command.
Nice! Installing PythonCall should never be necessary, it is always installed in the Julia environment used by JuliaCall.
You could make a PR to the PythonCall FAQ with this.
We could also bundle most of this code under a juliacall.blender
module.
Thanks!
Edited (and linked to a future editable gist).
I would say this FAQ entry Julia inside Python inside Blender · GitHub already covers this.
Regarding the juliacall.blender module, what would go there, the code after import juliacall
?
BTW, I am still experimenting with ways to make REPL IO a little faster.
cdsousa:
Regarding the juliacall.blender module, what would go there, the code after import juliacall
?
Yeah exactly, could be a function like juliacall.blender.start_julia_repl()
. Or at least a link to your gist from the FAQ.