Possible suggestion for docs
I had some issues getting setup, but I documented the steps I had to take and I'm just wondering if this would be useful for the docs. It could be too specific to my system but let me know what you think. I won't be offended either way! Thanks for the great library in any case :).
========================================...The write-up...==========================================
# Getting started (!?)
For me, there were some teething issues to get up and running. I got there in the end though and so consider this a ’how-to’ guide for those who have similar troubles. Most of the examples are system independent, but example path manipulation is restricted to linux-based installations.
<a id="orgd32c45b"></a>
# Install basilisp-blender
Follow the [basilisp-blender doc](https://github.com/ikappaki/basilisp-blender?tab=readme-ov-file), i.e. Run \`blender\` and in the scripting interface try to install the Python package.
pip install basilisp-blender
If this works out, celebrate, and then skip to ’Start Server’.
If you get something like the below, then Blender is probably using the ’system’ Python setup and your OS is (somewhat sensibly) blocking you from modifying it.
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
python-xyz', where xyz is the package you are trying to
install.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
<a id="org5ef9387"></a>
# Find Blender’s Python path
Whether for the previous or another reason, it might be worth checking what Python binary Blender is using and where this is. Run the following in the Blender console.
import sys
print(sys.executable)
If Blender is indeed using the system Python, or if it’s using an environment that you can’t modify, then you’ll have to create a virtual environment.
<a id="org16f77ca"></a>
# Create virtual environment
I recommend (for what that’s worth) using the [poetry](https://python-poetry.org/) tool for managing your Python deps and environment.
poetry new blender
poetry shell
poetry add basilisp-blender
Unless you’ve changed the defaults, the virtual environment may be stored centrally. You can find out where that is with the following command.
From now on, you should start Blender from **inside** the virtual environment.
<a id="org1447eb7"></a>
# Locate environment libraries
poetry env info --path
Go to that location and find the path to the installed packages: something like “../site-packages”. My packages were stored in “~/.cache/pypoetry/virtualenvs/blender-3B2xtVHD-py3.12/lib/python3.12/site-packages”. I would recommend using the **absolute path** in all of these examples though. I use the tilde simply for illustration (and to remind you not to try using my home directory).
<a id="org001deda"></a>
# Add to path
Now add this location to a \`PYTHONPATH\` that Blender will see.
export PYTHONPATH=~/.cache/pypoetry/virtualenvs/blender-3B2xtVHD-py3.12/lib/python3.12/site-packages:$PYTHONPATH
source ~/.zshrc
<a id="org905ae0a"></a>
# Manually add path to Blender
Now if, like for me, something is still wrong, then you might need to add the path directly. If so, input the following code in the Blender console or run it in a Blender script.
import sys
print(sys.path)
sys.path.append("~/.cache/pypoetry/virtualenvs/blender-3B2xtVHD-py3.12/lib/python3.12/site-packages")
from basilisp_blender.eval import eval_str
eval_str("(+ 1 2)")
# => 3
If that now works, congratulations! Don’t stop now though, because a big advantage of using basilisp-blender in the first place is to setup a well-integrated REPL.
<a id="org5e6fc27"></a>
# Start server
Now, instead of the above code, start a server.
from basilisp_blender.nrepl import server_start
shutdown_fn = server_start(host="127.0.0.1", port=8889)
<a id="org632ffc4"></a>
# Connect from emacs
You should now be able to connect to this server using the weapon (editor) of your choice. For emacs, consider the [cider docs](https://docs.cider.mx/cider/platforms/basilisp.html), i.e. go to your poetry environment, run
(cider-connect)
and choose the correct port for localhost.
If you dout your basilisp in general, then you can jack-in to a new REPL by using
(cider-jack-in-universal) ;; with numerical argument, 5
and choosing \`basilisp\`. I mention it here as you might be new to basilisp in general and not just it’s integration with Clojure.
<a id="org0ab7144"></a>
# Verify that it’s working!
Try the following.
(ns scratch
"A test-bed for Blender-ing with Clojure(-ish)."
(:import bpy))
(.select-all bpy.ops/object )
(.select-all bpy.ops/object ** :action "DESELECT")
If that works as you would expect then you are good to eval s-expressions to your heart’s content!
Knowing that it’s working, you can add the server add-on for convenience and try the more interesting examples, outlined in the [docs](https://github.com/ikappaki/basilisp-blender?tab=readme-ov-file).
关闭于 2025-02-09 2 条评论