🔗Installation script
Since manually downloading and extracting Blender doesn't install the blender.desktop
file you won't have a shortcut for it in your menu. Nor will pip
be setup for use with the python version Blender ships (it is independent of the Python installed on your system). Also it would be nice to store the location of Blender's custom Python executable in a variable, to make interacting with it easier.
Since this needs to be done every time you want to upgrade to a new version of Blender, I made a script.
🔗What it does
- downloads and extracts Blender to a specified location
- finds the path for Blender Python (no more digging around for it)
- sets up and installs the
blender.desktop
file (so you have a nice little shortcut for it) - ensures
pip
is installed - appends
BPY
,BLENDER_PATH
, andBLENDER_VERSION
to your.bashrc
file so you can easily find Blender
🔗Installing
At least on Linux it's not too hard to automate this setup.
-
Download install_blender.sh
-
Open a terminal to the directory where you downloaded the
install_blender.sh
script -
Make the script executable
chmod +x install_blender.sh
-
Specify the version to install and where to install it
Find download link
To find the url for the blender
.tar.xz
archive:- Go to Blender.org > About > Website
- Choose a mirror from the section titled External Mirrors
- Choose the release folder
- Choose the folder with the latest version
- Copy the link for the file ending with
-linux-x64.tar.xz
export BLENDER_URL=https://mirror.clarkson.edu/blender/release/Blender3.3/blender-3.3.1-linux-x64.tar.xz export BLENDER_INSTALL=$HOME/bin/blender/
-
Run the
install_blender.sh
script./install_blender.sh
I got this error, but it still works:
🔗Testing it out
Let's make sure it worked
-
After adding the lines to your
.bashrc
file that were suggested by the install script, open a new terminal -
You can install any module but as an example I will use Pillow:
"$BPY" -m pip install --upgrade pillow
Note: got another error here but it still works
-
Open blender and click the
Scripting
workspace -
In Blender's Python console type:
import PIL
It should just import the module without any errors.
🔗Importing local Python files
Frustratingly, Blender's python will not automatically resolve imports for local files. To get around this I append the .blend
file's path to sys.path
.
To automatically add the current file's path
- Download import_cur_path.py
- Copy it to your
scripts/startup
folder
Or run this to download the file directly to your scripts/startup/
folder:
curl -o "$BLENDER_PATH/$BLENDER_VERSION/scripts/startup/import_cur_path.py" "https://vishusandy.github.io/assets/blender_python/import_cur_path.py"
Or manually
Paste the following into your python console:
import sys
import os
import bpy
dir = os.path.dirname(bpy.data.filepath)
if not dir in sys.path:
sys.path.append(dir)
Now you can import python scripts from the folder where your .blend
file is saved.
For example, if you had a python file called zebra.py
, in the same directory as your .blend
file, you would import it like:
import zebra