-
Notifications
You must be signed in to change notification settings - Fork 10
/
install_blender_python_module.py
48 lines (40 loc) · 1.27 KB
/
install_blender_python_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import subprocess
import os
import platform
import bpy
def isWindows():
return os.name == 'nt'
def isMacOS():
return os.name == 'posix' and platform.system() == "Darwin"
def isLinux():
return os.name == 'posix' and platform.system() == "Linux"
def python_exec():
if isWindows():
import sys
return os.path.join(sys.prefix, 'bin', 'python.exe')
elif isMacOS():
import sys
try:
# 2.92 and older
path = bpy.app.binary_path_python
except AttributeError:
# 2.93 and later
path = sys.executable
return os.path.abspath(path)
elif isLinux():
import sys
return os.path.join(sys.prefix, 'bin', 'python3.11')
else:
print("sorry, still not implemented for ", os.name, " - ", platform.system)
def installModule(packageName):
python_exe = python_exec()
try:
subprocess.call([python_exe, "import ", packageName])
except:
# upgrade pip
subprocess.call([python_exe, "-m", "ensurepip"])
subprocess.call([python_exe, "-m", "pip", "install", "--upgrade", "pip"])
# install required packages
subprocess.call([python_exe, "-m", "pip", "install", packageName])
installModule("pygame")