summaryrefslogtreecommitdiff
path: root/required_modules.py
blob: 5eb1604b5b09bb0a9cf6bb6ecb04fc6e6684a462 (plain)
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
49
50
51
import bpy, numpy, subprocess
from . import file_ops

# 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)

  # 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__))

# unregister func
def unregister(): 
  return