"ModuleNotFoundError: No module named 'bpy_types'" when building as Python module #58069

Closed
opened 2018-11-26 22:34:42 +01:00 by Benjamin Humpherys · 16 comments

I've been trying to build Blender as a Python module, and keep running into the same error on both Mac and windows on both master and Blender2.8. I follow the build instructions on the wiki and updating CMakeLists.txt according to this BSO answer. Here is the most recent output after running make update && make just now on macOS Mojave:

admin@Benjamin-H-Macbook-Pro > ~/Projects/blender-build/build_darwin/bin > python3
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bpy

Color management: using fallback mode for management
BLT_lang_init: 'locale' data path for translations not found, continuing
bpy: couldnt find 'scripts/modules', blender probably wont start.
Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module

Surrounding the import statement with try:catch: doesn't do anything, crashing instead of throwing a python error. I've tried building blender normally and that does succeed, and I am able to import bpy and everything else without a problem within the scripting console. This is true on both Mac and Windows. I've tried adding the scripts/modules folder to sys.path but this does not do anything.

I've been trying to build Blender as a Python module, and keep running into the same error on both Mac and windows on both master and Blender2.8. I follow the [build instructions on the wiki](https:*wiki.blender.org/wiki/Building_Blender) and updating CMakeLists.txt according to [this BSO answer.](https:*blender.stackexchange.com/questions/117200/how-to-build-blender-as-a-python-module) Here is the most recent output after running `make update && make` just now on macOS Mojave: ``` admin@Benjamin-H-Macbook-Pro > ~/Projects/blender-build/build_darwin/bin > python3 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bpy Color management: using fallback mode for management BLT_lang_init: 'locale' data path for translations not found, continuing bpy: couldnt find 'scripts/modules', blender probably wont start. Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly. ModuleNotFoundError: No module named 'bpy_types' ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module ModuleNotFoundError: No module named 'bpy_types' ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module ``` Surrounding the import statement with `try:catch:` doesn't do anything, crashing instead of throwing a python error. I've tried building blender normally and that does succeed, and I am able to import `bpy` and everything else without a problem within the scripting console. This is true on both Mac and Windows. I've tried adding the `scripts/modules` folder to `sys.path` but this does not do anything.

Added subscriber: @brhumphe

Added subscriber: @brhumphe

Added subscribers: @ideasman42, @mont29

Added subscribers: @ideasman42, @mont29
Campbell Barton was assigned by Bastien Montagne 2018-11-29 11:03:16 +01:00

@ideasman42 think you are still maintaining that experimental feature? ;)

@ideasman42 think you are still maintaining that experimental feature? ;)

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

@mont29, yes.

@brhumphe you need to 'make install'. manually copying bpy.so will give this error.

closing.

@mont29, yes. @brhumphe you need to 'make install'. manually copying `bpy.so` will give this error. closing.

@ideasman42 Using make install does not fix the issue. I just did a fresh build and the results were the same:

git pull
make update
make
cd ../build_darwin
make install

I created a virtual environment using these instructions from @dr.sybren , sim linking both blender/release and boy.so inside of the site-packages directory of the virtual environment:

cd venv/lib/python3.7/site-packages/
ln -s ~/Projects/blender-build/build_darwin/bin/bpy.so
ln -s ~/Projects/blender-build/blender/release

Attempting to import bpy results in the following:

../../../bin/python3 -c "import bpy"
Color management: using fallback mode for management
BLT_lang_init: 'locale' data path for translations not found, continuing
bpy: couldnt find 'scripts/modules', blender probably wont start.
Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module
F1129 15:51:07.112875 255042944 utilities.cc:322] Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
***Check failure stack trace:***
    @        0x105c2202f
    @        0x105c1e609
    @        0x105c25b2f
    @        0x105b44af1
    @        0x103cc49cd
    @        0x1040e7437
    @        0x103685f9c
    @        0x103689b56
    @        0x103742590
    @        0x10373dea3
    @        0x10373d6a8
    @        0x10365e398
    @        0x10365e081
    @        0x10371a9f2
    @        0x10371e096
    @        0x10365dd81
    @        0x10371d5bb
    @        0x10371a560
    @        0x10365e1f0
    @        0x10371d5bb
    @        0x10371a546
    @        0x10365e1f0
    @        0x10371d5bb
    @        0x10371a601
    @        0x10365e1f0
    @        0x10371d5bb
    @        0x10371a601
    @        0x10365e1f0
    @        0x10371d5bb
    @        0x10371a601
    @        0x10365e1f0
    @        0x10365d7e4
[1]    39508 abort      ../../../bin/python3 -c "import bpy"
@ideasman42 Using `make install` does not fix the issue. I just did a fresh build and the results were the same: ``` git pull make update make cd ../build_darwin make install ``` I created a virtual environment using [these instructions from @dr.sybren ](https://stuvel.eu/files/bconf2016/#/10), sim linking both `blender/release` and `boy.so` inside of the `site-packages` directory of the virtual environment: ``` cd venv/lib/python3.7/site-packages/ ln -s ~/Projects/blender-build/build_darwin/bin/bpy.so ln -s ~/Projects/blender-build/blender/release ``` Attempting to import bpy results in the following: ``` ../../../bin/python3 -c "import bpy" Color management: using fallback mode for management BLT_lang_init: 'locale' data path for translations not found, continuing bpy: couldnt find 'scripts/modules', blender probably wont start. Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly. ModuleNotFoundError: No module named 'bpy_types' ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module ModuleNotFoundError: No module named 'bpy_types' ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module ModuleNotFoundError: No module named 'bpy_types' ERROR (bpy.rna): /Users/admin/Projects/blender-build/blender/source/blender/python/intern/bpy_rna.c:6662 pyrna_srna_ExternalType: failed to find 'bpy_types' module F1129 15:51:07.112875 255042944 utilities.cc:322] Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice! ***Check failure stack trace:*** @ 0x105c2202f @ 0x105c1e609 @ 0x105c25b2f @ 0x105b44af1 @ 0x103cc49cd @ 0x1040e7437 @ 0x103685f9c @ 0x103689b56 @ 0x103742590 @ 0x10373dea3 @ 0x10373d6a8 @ 0x10365e398 @ 0x10365e081 @ 0x10371a9f2 @ 0x10371e096 @ 0x10365dd81 @ 0x10371d5bb @ 0x10371a560 @ 0x10365e1f0 @ 0x10371d5bb @ 0x10371a546 @ 0x10365e1f0 @ 0x10371d5bb @ 0x10371a601 @ 0x10365e1f0 @ 0x10371d5bb @ 0x10371a601 @ 0x10365e1f0 @ 0x10371d5bb @ 0x10371a601 @ 0x10365e1f0 @ 0x10365d7e4 [1] 39508 abort ../../../bin/python3 -c "import bpy" ```

This may be OSX spesific then.

Try using a system call tracing tool (strace on Linux), to see which directories are being checked for immediately before the message:

bpy: couldnt find 'scripts/modules', blender probably wont start.

This may be OSX spesific then. Try using a system call tracing tool (strace on Linux), to see which directories are being checked for immediately before the message: `bpy: couldnt find 'scripts/modules', blender probably wont start.`

This is not OSX-specific, I have the same issue on Windows too, most recently with build 84285c1e3440. Here is the system trace from Procmon on windows: failed_bpy_import.CSV

This is not OSX-specific, I have the same issue on Windows too, most recently with build 84285c1e3440. Here is the system trace from Procmon on windows: [failed_bpy_import.CSV](https://archive.blender.org/developer/F5782088/failed_bpy_import.CSV)

@brhumphe On windows it's looking for: C:\ProgramData\Blender Foundation\Blender\2.79\scripts\modules

This is from Blender's release/scripts path.

@brhumphe On windows it's looking for: `C:\ProgramData\Blender Foundation\Blender\2.79\scripts\modules` This is from Blender's `release/scripts` path.

Why is it looking there instead of searching the sys.path of the python interpreter?

Why is it looking there instead of searching the `sys.path` of the python interpreter?

@brhumphe

I rather not get into details of why Blender is setup the way it is.
In brief, this works well for an application that embeds Python, but not so well for a Python module.

This can be made to work as long as the install target copies files to the correct locations. If you get this working, it'd be good to apply changes to CMake.

I keep this working on my system. The reason this bug remains closed is this feature is experimental and difficult to properly support - when Python devs run into issues.

@brhumphe I rather not get into details of why Blender is setup the way it is. In brief, this works well for an application that embeds Python, but not so well for a Python module. This can be made to work as long as the install target copies files to the correct locations. If you get this working, it'd be good to apply changes to CMake. I keep this working on my system. The reason this bug remains closed is this feature is experimental and difficult to properly support - when Python devs run into issues.

@ideasman42 Fair enough. I can see how changing it to work with sys.path could be more effort than it’s worth. It’s good to know what the issue is, this was bugging me for weeks! If I find a solution I’ll pass it along.

@ideasman42 Fair enough. I can see how changing it to work with `sys.path` could be more effort than it’s worth. It’s good to know what the issue is, this was bugging me for weeks! If I find a solution I’ll pass it along.

Added subscriber: @doppioslash

Added subscriber: @doppioslash
Member

Added subscriber: @ankitm

Added subscriber: @ankitm
Member

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'
Member

The error is because of the wrong command on the wiki.
It should be similar for Blender.app which is Blender.app/Contents/Resources/2.93/scripts/addons. For python modules it should look like lib/python3.9/Resources/2.93/scripts/addons. The old command on the wiki produced lib/python3.9/Resources/scripts/addons.

Windows wiki was updated for this in November, macOS was updated just now.

The error is because of the wrong command on the wiki. It should be similar for Blender.app which is `Blender.app/Contents/Resources/2.93/scripts/addons`. For python modules it should look like `lib/python3.9/Resources/2.93/scripts/addons`. The old command on the wiki produced `lib/python3.9/Resources/scripts/addons`. Windows wiki was updated for this in November, macOS was updated just now.
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 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#58069
No description provided.