Failing to import Blender as a python module #50359

Closed
opened 2017-01-02 11:40:34 +01:00 by Rainer Trummer · 8 comments

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.

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.
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @RainerTrummer

Added subscriber: @RainerTrummer

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2017-01-06 12:32:45 +01:00

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.

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](http:*blenderartists.org/) or [blender.stackexchange.com](http:*blender.stackexchange.com/).
Author

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

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

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!

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!
Author
I meant this guide: http://www.gizmoplex.com/wordpress/compile-blender-as-python-module/
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#50359
No description provided.