summaryrefslogtreecommitdiff
path: root/required_modules.py
diff options
context:
space:
mode:
authorOwl <isaclien9752@gmail.com>2025-08-25 21:35:45 -0400
committerOwl <isaclien9752@gmail.com>2025-08-25 21:35:45 -0400
commit2f71ead735326d2f79ebeec1a739943da6e95b41 (patch)
tree87943ff992633a2d7df941b82b818c2e7089a17a /required_modules.py
parent8fd537dfe7cc170290b1043a1e601699fc14c8fb (diff)
downloadblenxy-2f71ead735326d2f79ebeec1a739943da6e95b41.tar.gz
blenxy-2f71ead735326d2f79ebeec1a739943da6e95b41.zip
setup blenxy to be able to "reload" without quitting blender
Diffstat (limited to 'required_modules.py')
-rw-r--r--required_modules.py86
1 files changed, 47 insertions, 39 deletions
diff --git a/required_modules.py b/required_modules.py
index 8aecc7d..5eb1604 100644
--- a/required_modules.py
+++ b/required_modules.py
@@ -1,43 +1,51 @@
-import bpy, numpy
-from subprocess import run
+import bpy, numpy, subprocess
from . import file_ops
-# get python's binary path (literally my saviour)
-py_bin = bpy.app.binary_path_python
-pip_install = [py_bin, "-B", "-m", "pip", "install",
- "--trusted-host", "pypi.python.org",
- "--trusted-host", "files.pythonhosted.org",
- "--trusted-host", "pypi.org",
- "-U", "--force-reinstall", "--only-binary", ":all:"]
-upd_mods = ["pip", "wheel", "setuptools"]
-new_mods = ["lxml"]
+# register func
+@bpy.app.handlers.persistent
+def register(dummy):
+ # get python's binary path (literally my saviour)
+ py_bin = bpy.app.binary_path_python
+ pip_install = [py_bin, "-B", "-m", "pip", "install",
+ "--trusted-host", "pypi.python.org",
+ "--trusted-host", "files.pythonhosted.org",
+ "--trusted-host", "pypi.org",
+ "-U", "--force-reinstall", "--only-binary", ":all:"]
+ upd_mods = ["pip", "wheel", "setuptools"]
+ new_mods = ["lxml"]
+
+ # try importing pip/lxml to trigger
+ # the module updating on failure
+ try:
+ import pip
+ import lxml
+ except:
+ # hecking install pip (ensurepip) + required modules
+ subprocess.run([py_bin, "-B", "-m", "ensurepip"])
+ # update basic modules then download new modules
+ subprocess.run(pip_install + upd_mods)
+ subprocess.run(pip_install + new_mods)
+ # rename numpy's installation folder (cannot delete the folder in windows)
+ file_ops.rename(numpy.__path__[0], numpy.__path__[0] + "_bad")
+ subprocess.run(pip_install + ["numpy==1.18.5"]) # install a newer version
+ print("First exit!")
+ bpy.ops.wm.quit_blender()
+ exit(0)
-try:
- import pip
- import lxml
-except:
- # hecking install pip (ensurepip) + required modules
- run([py_bin, "-B", "-m", "ensurepip"])
- # update basic modules then download new modules
- run(pip_install + upd_mods)
- run(pip_install + new_mods)
- # rename numpy's installation folder (cannot delete the folder in windows)
- file_ops.rename(numpy.__path__[0], numpy.__path__[0] + "_bad")
- run(pip_install + ["numpy==1.18.5"]) # install a newer version
- print("First exit!")
- bpy.ops.wm.quit_blender()
- exit(0)
+ # print module's versions installed
+ print("pip %s is installed!" % (pip.__version__))
+ print("lxml %s is installed!" % (lxml.__version__))
+ # for those who have installed blenxy before, update numpy
+ # hacky way to do it but it is the only way that works
+ if (numpy.__version__ != "1.18.5"):
+ # rename numpy's installation folder (cannot delete the folder in windows)
+ file_ops.rename(numpy.__path__[0], numpy.__path__[0] + "_bad")
+ subprocess.run(pip_install + ["numpy==1.18.5"]) # install a newer version
+ print("Second exit!")
+ bpy.ops.wm.quit_blender()
+ exit(0)
+ print("numpy %s is installed!" % (numpy.__version__))
-# print module's versions installed
-print("pip %s is installed!" % (pip.__version__))
-print("lxml %s is installed!" % (lxml.__version__))
-# for those who have installed blenxy before, update numpy
-# hacky way to do it but it is the only way that works
-if (numpy.__version__ != "1.18.5"):
- # rename numpy's installation folder (cannot delete the folder in windows)
- file_ops.rename(numpy.__path__[0], numpy.__path__[0] + "_bad")
- run(pip_install + ["numpy==1.18.5"]) # install a newer version
- print("Second exit!")
- bpy.ops.wm.quit_blender()
- exit(0)
-print("numpy %s is installed!" % (numpy.__version__))
+# unregister func
+def unregister():
+ return