Page MenuHome

Failing to import Blender as a python module
Closed, ArchivedPublic

Description

I have successfully managed to build Blender as a Python module using the pre-existing 'make bpy' command both on Linux x64 and Windows 7 x64. Importing the bpy module later on works nicely from within Linux, even when configuring Eclipse to do so using the PyDev extension. I get very clean and reliable code completion. However, when trying to import bpy on Windows from a Python shell, the following error is thrown:

importing Python first

C:\Program Files (x86)\Microsoft Visual Studio 12.0>python

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

get the current paths

import sys
sys.path

['', 'C:\\Program Files\\Python35\\python35.zip', 'C:\\Program Files\\Python35\\DLLs', 'C:\\Program Files\\Python35\\lib', 'C:\\Program Files\\Python35', 'C:\\Program Files\\Python35\\lib\\site-packages']

append the build path

sys.path.append('C:\\blender-git\\build_windows_Bpy_x64_vc12_Release\\bin\\Release')
sys.path.append('C:\\blender-git\\build_windows_Bpy_x64_vc12_Release\\bin\\Release\\2.78\\scripts')
sys.path.append('C:\\blender-git\\build_windows_Bpy_x64_vc12_Release\\bin\\Release\\2.78')

import the module

import bpy

bpy: couldnt find 'scripts/modules', blender probably wont start.
Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.
ImportError: No module named 'bpy_types'
ImportError: No module named 'bpy_types'
pyrna_srna_ExternalType: failed to find 'bpy_types' module
ImportError: No module named 'bpy_types'
ImportError: No module named 'bpy_types'
pyrna_srna_ExternalType: failed to find 'bpy_types' module
ImportError: No module named 'bpy_types'
pyrna_srna_ExternalType: failed to find 'bpy_types' module
F0102 11:21:26.276347 8560 utilities.cc:322] Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
Check failure stack trace:

At this point, Python crashes and gives me that infamous 'Send Information' window.

Event Timeline

Bastien Montagne (mont29) changed the task status from Unknown Status to Archived.Jan 6 2017, 12:32 PM
Bastien Montagne (mont29) claimed this task.

I would suggest you first try from a raw python console (from MS command line, not from MSVC one).

Besides, thanks for the report, but I see no Blender bug here, this is a problem of python not finding modules, i.e. not having the right paths for some reason, configuration issue.

Please seek support on user forums like blenderartists.org or blender.stackexchange.com.

Thanks for your feedback,I will try your suggestions next Monday when I am back in the office.

Just verified the suggestions. Using the raw Pyhton console made no difference, import errors would remain the same. But following the guide here **http://www.gizmoplex.com/wordpress/compile-blender-as-python-module/** (especially the part of copying the needed libs over to the Python35 directory) made it work. Can now successfully use the bpy build!