Closed chiaravalle closed 3 years ago
Thank you, I will update the Wiki to this effect!
I do like this version:
import subprocess
import sys
try:
import pygame as pg
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", 'pygame'])
finally:
import pygame as pg
Which presumably I could add to the scripts where PyGame is called or the __init.py__
file? I'll have a play and see what happens...
Cheers, Clock.
PS. sorry for delay in replying...
No problem for the delay. Yes, your version seems more appropriate, as it will install pygame the first time the AddOn is launched.
OK, pip is not installed in a new install...
So if I ensure pip first, it works, is there a way to ensure pip in the init.py file?
Dunno, sorry. I made the script after StackOverflow, but I know nothing about Python
No Problem, I'll play with it!
You do it like this:
import subprocess
import sys
try:
import pip
except ImportError:
subprocess.check_call([sys.executable, "-m", "ensurepip"])
try:
import pygame as pg
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", 'pygame'])
finally:
import pygame as pg
You can install pip modules from the Blender's Python console, by just writing 2 lines of code:
Credits: https://stackoverflow.com/questions/12332975/installing-python-module-within-code Tested on Blender 2.93 with Windows 10.
Cheers B)