blender-gpt/gpt_pkg.py

55 wiersze
1.4 KiB
Python

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():
return os.path.join(sys.prefix, 'bin', 'python.exe')
elif isMacOS():
try:
# 2.92 and older
path = bpy.app.binary_path_python
except AttributeError:
path = sys.executable
return os.path.abspath(path)
elif isLinux():
return os.path.join(sys.prefix, 'sys.prefix/bin', 'python')
else:
print("sorry, still not implemented for ",
os.name, " - ", platform.system)
def installModule(packageName):
python_exe = python_exec()
try:
subprocess.check_call([python_exe, "-c", "import " + packageName])
print(f"{packageName} already installed")
except subprocess.CalledProcessError:
# upgrade pip
subprocess.call([python_exe, "-m", "ensurepip"])
subprocess.call(
[python_exe, "-m", "pip", "install", "--upgrade", "pip"])
# install required packages and upgrade
subprocess.call([python_exe, "-m", "pip", "install",
"--upgrade", packageName])
installModule('openai')