🔗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.desktopfile (so you have a nice little shortcut for it) - ensures
pipis installed - appends
BPY,BLENDER_PATH, andBLENDER_VERSIONto your.bashrcfile 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.shscript -
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.xzarchive:- 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.shscript./install_blender.shI got this error, but it still works:
Everything still works - Successfully installed pip
🔗Testing it out
Let's make sure it worked
-
After adding the lines to your
.bashrcfile 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 pillowNote: got another error here but it still works
Ignore this message -
In Blender's Python console type:
import PIL
🔗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/startupfolder
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