I'm using Mac OS X with PyCharm and Python 3.5.1 and Blender 2.77.
I'm using Blender with Python scripts. I understand that in order to run Python scripts that use Blender (i.e. that imports bpy
), I need to run it from command line using blender -b -P /path/to/my_python_script.py
(although I don't really know why). That's all fine and it works, but I wish I could just run it from inside Python, because I use these scripts with other non-Blender Python code and I like to use PyCharm to debug and to do pretty much everything. I understand that I can't just run the Blender Python script from PyCharm, but I thought I'd try anyway. I took care to ensure that PyCharm can see the bpy
module by editing the "Project Structure" settings in "Preferences" to include the parent directory in which the bpy
module lives, which on my machine is /Applications/blender.app/Contents/Resources/2.77/scripts/modules
. However, when I try to run the script, it gives ImportError: No module named '_bpy'
. I followed the source of the error and the culprit was a line in the __init__.py
file in the bpy
module (whose location on my machine is /Applications/blender.app/Contents/Resources/2.77/scripts/modules/bpy/__init__.py
); the line is:
from _bpy import types, props, app, data, context
So I tried to search for the module _bpy
on my machine, and couldn't find it anywhere. So it seems to be importing things from a module that doesn't exist. However, I know that my script works because I've successfully run it in Blender.
So my question is, what witchcraft is going on with the mysterious _bpy
module, that neither I nor PyCharm can find, but that the Blender app doesn't have a problem with? I looking to gain a general understanding of what might be going on here, so educated guesses (as well as precise answers obviously) are welcome.