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
- 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
printandshow*methods - in this setup, I use
entras 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.
# 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_vscodeI use entr to watch files for changes and reload the preview. On Debian, install it with
sudo apt install entrThe 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- Start the rendering server in one terminal:
python -m ocp_vscode
- Open your browser at the URL provided (ending with
/viewer) - Start the file watcher in another terminal:
ls *.py | entr -s "python myfile.py"
- Edit
myfile.pywith your prefered editor
I use entr with its limitations: the entire file is re-loaded, and it can take some time. Here are some alternatives:
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
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