Created
January 22, 2024 15:52
-
-
Save SuddenDevelopment/c28ceafcb8dc2075fb7a516521c6b7e7 to your computer and use it in GitHub Desktop.
pip install from inside Blender Scripting tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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