# Running Julia inside Blender through VSCode (using PythonCall/JuliaCall)

**URL:** <https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838>\
**Category:** Specific Domains\
**Tags:** python, vscode, juliacall, pythoncall, blender\
**Created:** [March 30, 2023, 11:24am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838 "2023-03-30T11:24:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [March 30, 2023, 11:24am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/1 "2023-03-30T11:24:12Z")

</div>

Hi all, I’ve been using a workflow that I came up with that consists of using Blender through its GUI and programmatically with Julia at the same time.

I usually develop in Julia using VSCode and its “execute line” and “execute cell” commands, so I was able to do that but with Julia running inside the Python that is running inside Blender, which allows me to interface with Blender itself through the Blender Python API (bpy module).

I’m dropping in here the instructions to set up such a workflow since this can be helpful to someone else or someone can even improve the usability of this.

# Running Julia inside Blender through VSCode (using PythonCall/JuliaCall)

## Install Blender

- **Install Blender into a user folder** (any folder where user has rights to write). This allows us to install Python packages with Blender’s pip into Blender’s internal Python “site-packages” folder.

## Install JuliaCall within Blender Python environment

- Open Blender and run this on the Blender’s Python console:

```python
import pip
pip.main(['install', 'juliacall'])

```

- This needs to be done only once on each new Blender installation.

## Connect a VSCode session to a Blender instance

- Open VSCode.
- Execute Blender from some terminal (may be a VSCode integrated terminal). This allows us to see Julia output there.
- In VSCode, call the command `Julia: Connect external REPL`.
- Copy the generated code and paste it into the indicated line of the following code

```python
c = r'''
PASTE CODE GENERATED BY `Julia: Connect external REPL` COMMAND INTO THIS LINE
'''

import sys
sys.ps1 = '>>> ' # make PythonCall believe that Python is interactive so that display uses terminal size
import juliacall
juliacall.Main.seval(c)

def julia_work():
    juliacall.Main.sleep(0.001)
    return 0.02

julia_timer = bpy.app.timers.register(julia_work, persistent=True)

```

- Copy the entire code above, paste it and run it on the Blender’s Python console.
- Check terminal for feedback and VSCode notification for successful connection.

## Profit!

- From now on, Julia code executed on that VSCode session with `Julia: Execute...` commands will run inside Julia inside Python inside Blender.
- That code can be related to package and environment management, using the `Pkg` module, for example:

```julia
import Pkg
Pkg.activate()
Pkg.add("PythonCall")

```

- Most useful, we can now call back into Blender from Julia!:

```julia
using PythonCall
bpy = pyimport("bpy")
scn = bpy.context.scene
objnames = [obj.name for obj in scn.objects]

```

- Blender GUI will still be usable and responsible, although it can freeze while Julia is doing computations.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [March 30, 2023, 7:23pm UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/2 "2023-03-30T19:23:01Z")

</div>

Cool! Could you make a PR to link to this post from the PythonCall FAQ please? [PythonCall.jl/faq.md at main · cjdoris/PythonCall.jl · GitHub](https://github.com/cjdoris/PythonCall.jl/blob/main/docs/src/faq.md)

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [March 30, 2023, 7:25pm UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/3 "2023-03-30T19:25:15Z")

</div>

Can you explain `julia_work`? Is it to keep Julia’s event loop going?

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [March 31, 2023, 9:55am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/4 "2023-03-31T09:55:55Z")

</div>

> [@cjdoris](#):
>
> Can you explain `julia_work`?

It seems that Python’s main thread (with GIL) is the Blender GUI thread too. So when something in Python is running the GUI is blocked and vice versa. As far as I understand the Julia main thread when starting through JuliaCall is the same one as Python. So no computation in Python or in Julia can constantly permanently hold the thread execution or the other parts will freeze.

`julia_work` is a callback that is set to be called by Blender with 0.02 secs timer interval. `juliacall.Main.sleep(0.001)` allows Julia schedule do its computations. I’ve tried `juliacall.Main.yield()` but that didn’t work. These times have been tunned empirically.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [March 31, 2023, 10:12am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/5 "2023-03-31T10:12:10Z")

</div>

> [@cjdoris](#):
>
> Could you make a PR to link to this post from the PythonCall FAQ

Done [Add link in faq.md to instructions to run Julia within Blender by cdsousa · Pull Request #288 · JuliaPy/PythonCall.jl · GitHub](https://github.com/cjdoris/PythonCall.jl/pull/288). I’m not sure if that was what you had in mind. Feel free to completely reformulate it.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [February 4, 2024, 12:58am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/6 "2024-02-04T00:58:05Z")

</div>

I’ve found yet another much better way to use Julia within Blender.

The idea is to launch JuliaCall with Blender’s Python and with it launch a Julia REPL in Blender’s terminal.  
Hence, we get a Julia REPL which is running inside Python inside Blender and has full access to Blender bpy API.

To do that, we must execute Blender from a terminal and pass it a small Python script to be run:

`blender.exe --python blender_julia.py`

where `blender_julia.py` contents are: (update version here: [Julia inside Python inside Blender · GitHub](https://gist.github.com/cdsousa/d820d27174238c0d48e5252355584172))

```python
# 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.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [February 4, 2024, 11:33am UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/7 "2024-02-04T11:33:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [February 4, 2024, 12:36pm UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/8 "2024-02-04T12:36:02Z")

</div>

Thanks!

Edited (and linked to a future editable gist).

I would say this FAQ entry [Julia inside Python inside Blender · GitHub](https://gist.github.com/cdsousa/d820d27174238c0d48e5252355584172) 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.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [February 4, 2024, 3:28pm UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/9 "2024-02-04T15:28:09Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [July 13, 2026, 6:56pm UTC](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/10 "2026-07-13T18:56:26Z")

</div>

For an update on this see [Running Julia inside Blender through VSCode (using PythonCall/JuliaCall) - #6 by cdsousa](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/6)

For a remote workflow (running standalone Julia in its own process and then connecting to Blender using rpyc) see [Controlling Blender from Julia using bpy and PythonCall.jl](https://discourse.julialang.org/t/controlling-blender-from-julia-using-bpy-and-pythoncall-jl/137707)
