I have built Blender’s API as a Python module, and produced a Release bpy.pyd. Upon placing this in Lib\site-packages\bpy. I can now import bpy successfully. However, I am unable to load any of the modules associated with bpy, for instance from bpy.types import Action, will give me an error ModuleNotFoundError: No module named 'bpy.types'. Similarly, after doing a import bpy, running a script with only the line bpy.types.Action gives the error: AttributeError: module 'bpy' has no attribute 'types'.
If I start up IPython, import bpy, then type bpy. in the console and hit Tab for auto-completion, no auto-complete options show up.
If I am interpreting the Python docs correctly, there is nothing more for me to do once I make Python aware of the bpy.pyd. So, what’s going wrong? Why is Python not aware of the “detail” contained in bpy.pyd?
You would also need to copy the DLLs and the .\2.92 directory as shown in the Wiki, but exclude the python3.dll and python37.dll.
The exact steps are:
In Blender’s git repository run make bpy
In the build folder you will find the bpy.pyd, BlendThumb.dll, libfftw3-3.dll, libgmp-10.dll, libgmpxx.dll, tbb.dll, tbbmalloc.dll, tbbmalloc_proxy.dll. These need to be copied into the directory where your python.exe is located, e.g. C:\Program Files\Python37.
In the build folder you will find the .\2.92 subdirectory that contains the scripts and data files. This directory needs to be copied into C:\Program Files\Python37 as well.
Hi @Robert , I am trying to follow your advice, but I’m not sure it’s still the way to do it. I build my bpy. My Python executable is located at: C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe
I added the .dll files & subdirectory that contains the scripts and data files to the same folder as the executable:
@KevinBurke could yout try again with a recent build from master? (if you weren’t doing this already)
The final result should now be a “bpy/” directory containing __init__.pyd on windows (making it a Python package). You should not have copy DLL’s about or rename files. Besides making sure the “bpy” directory is in Python’s search path.
That used to be the very hacky and unclean way of getting it to work.
I have tested this just now and the current steps are as Campbell said. Since it now builds a proper module you can either add it to your PYTHONPATH environment variable or to your sys.path prior to import.
Build the Python module make bpy
Open a terminal and run python to get the interpreter prompt
import sys and then append both the path to <some prefix>\build_windows_Bpy_x64_vc16_Release\bin\Releaseand<some prefix>\build_windows_Bpy_x64_vc16_Release\bin\Releas\bpy with calls to sys.path.append(<put string var here>).
Import the module with import bpy
These steps are not necessary when the paths are in PYTHONPATH since Python will already check there on its own (they are automatically getting added to sys.path).