pythonblender

Blender 4.2, Python 3.12.4 - Python script import Blender


I inherited a Python script which, I suppose, was working (with previous? versions of Blender and Python). Now I got following message:

Python: Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Blender'

Parts of script which may be helpful to find out the reason of above. INSTRUCTIONS indicate that script should be loaded and executed inside Blender:

#!BPY

...

# INSTRUCTIONS (You definitely want to read this!): 
#      Once the script is loaded in Blender, hit alt-p. This will bring up
#      the main interface panel...

...

import math
import Blender
from Blender import *
from Blender import NMesh
from Blender.Draw import *
from Blender.BGL import *
from Blender import Material
from Blender import Window

...

After installing Blender 4.2 the Blender.py script location is (in case it is important):

C:\Program Files\Blender Foundation\Blender 4.2\4.2\scripts\presets\keyconfig

Tried to find answers on web but with no success. I hope for explanation of that crash and tips on how to deal with it.


Solution

  • The imports that you script is relying on is not part of the Blender 4.2 release. Looking through the API document the latest version that does have those files appear to be 2.49 (2009-5-30). The current API lives in the bpy namespace. You either need to downgrade Blender or the port the script the current API.