Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created January 22, 2024 15:52
Show Gist options
  • Save SuddenDevelopment/c28ceafcb8dc2075fb7a516521c6b7e7 to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/c28ceafcb8dc2075fb7a516521c6b7e7 to your computer and use it in GitHub Desktop.
pip install from inside Blender Scripting tab
import subprocess
import sys
import importlib.util
# RUN THIS INSIDE BLENDER SCRIPTING TAB
def addPip(strLibrary, reinstall=False):
if importlib.util.find_spec(strLibrary) is None:
# Ensure pip is installed
try:
subprocess.check_call(
[sys.executable, "-m", "ensurepip", "--upgrade"])
except subprocess.CalledProcessError as e:
print(f'Caught CalledProcessError while trying to ensure pip is installed')
print(f' Exception: {e}')
print(f' {sys.executable}')
# return False
pass
mode = "--upgrade"
if reinstall:
mode = "--force-reinstall"
sub = subprocess.run(
[sys.executable, "-m", "pip", "install", mode, strLibrary])
if sub.returncode != 0:
return False
return True
# CHANGE THIS TO WHATEVER PACKAGE IS MISSING
addPip('pillow')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment