Skip to content

Instantly share code, notes, and snippets.

@mtancoigne
Last active November 22, 2025 20:04
Show Gist options
  • Select an option

  • Save mtancoigne/9e2b7cdfb13f2c5a2a405cfb059e9b87 to your computer and use it in GitHub Desktop.

Select an option

Save mtancoigne/9e2b7cdfb13f2c5a2a405cfb059e9b87 to your computer and use it in GitHub Desktop.
Alternate setup for build123d

Build123d alternate setup

The community recomends to use VSCode with the ocp_vscode plugin to use build123d. If you prefer not to use VSCode/Codium to develop, but keep using the awesome renderer from ocp_vscode, it's possible.

The general idea is to:

  • use ocp_vscode to preview the models (in a web browser)
  • use your favourite editor
  • optionally have the preview update when you save your work

I use pyenv to manage Python environments; adapt to your preference.

I'm on linux so I have no clue for the corresponding tools on windows/mac

Limitations of this setup

  • Python files are reloaded, there is no cell support (as with Jupyter). This may lead to waiting times depending on your machine. Alternatives are listed at the end of this file.
  • obviously, the debugging feature provided by ocp_vscode plugin in VSCode is not available too. I debug with print and show* methods
  • in this setup, I use entr as a file watcher. It works great but if a new file is created, the command should be restarted if you want to update preview when the new file gets modified.

Python setup

# Prepare environment
pyenv install 3.13
pyenv virtualenv 3.13 build123d

# Add dependencies
pip install build123d # or refer to the git repo to have the last version
pip install ocp_vscode

File watcher

I use entr to watch files for changes and reload the preview. On Debian, install it with

sudo apt install entr

The usage is to pipe a file list to it and provide a command to execute when one of the file changes:

ls *.py | entr -s "python myfile.py"
# or
cat list.txt | entr -s "python myfile.py"
# or check the manual for other examples of how to select files

Code!

  1. Start the rendering server in one terminal:
    python -m ocp_vscode
  2. Open your browser at the URL provided (ending with /viewer)
  3. Start the file watcher in another terminal:
    ls *.py | entr -s "python myfile.py"
  4. Edit myfile.py with your prefered editor

Alternative file watchers

I use entr with its limitations: the entire file is re-loaded, and it can take some time. Here are some alternatives:

Alternatives for code cell support

List of editors that supports code cells. When using these, you should not use a file watcher and leave the IDE do its work:

  • Spyder IDE (site and repo)
  • Jetbrain's PyCharm pro (not opensource)
  • VSCode and VSCodium (well... the whole point of this gist was not to use it...)
  • NeoVim plugin: NotebookNavigator
@jdegenstein
Copy link

jdegenstein commented Oct 23, 2025

FYI I found this project https://pypi.org/project/watchmagic that allows for combining file watching with ipython, which I think should automatically cache imports and (greatly) speed up re-running the script.

Turns out that is not the case unfortunately. I felt inspired and created another file watcher solution and showed it on discord

@jdegenstein
Copy link

OK, I posted my solution in a repo here https://github.com/jdegenstein/filewatcher123d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment