1

I have found online 2 commands that load a file and convert it in another format; the next step is to run a script for all the files in a folder.

Althought these commands require bpy, which I can't import.

I did install python 3.4 and the latest blender for Windows. Why Python can't find the bpy library? I am used to work with pip on unix systems, and this is my first attempt at using python on windows.

In the worst case I will just use linux via VM, but since I am running on windows; I would rather find out how you work with bpy.

UPDATE:

I did check the similar topic related to errors when importing bpy; in that case the module is not present, while in my case I can see the module in the Blender scripts folder.

I did copy the scripts to the Python3.4 folder, and when I run the import statement now it can see it but complains about the fact that there is no _bpy module. Not sure if there is a python version issue or some other problem.

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import bpy
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import bpy
  File "C:\Python34\Scripts\bpy\__init__.py", line 38, in <module>
    from _bpy import types, props, app, data, context
ImportError: No module named '_bpy'
  • You can install pip on windows :) – justanotherdev Dec 06 '15 at 06:58
  • I know :) Pip has bpy but I see it installed already in the blender folder; so installing it via pip would probably cause some sort of cosmic issue for windows. –  Dec 06 '15 at 07:07
  • Possible duplicate of [Import Error for BPY module in python](http://stackoverflow.com/questions/32800927/import-error-for-bpy-module-in-python) – sambler Dec 06 '15 at 08:21
  • @sambler: not a dupe; in that case the module is not there; in my case I can see it. I tried to move it in the python folder and when I run the script it says that there is no module called "_bpy". I suspect I need to try with a different python version, or there is something else that I am not doing right –  Dec 06 '15 at 09:16
  • 1
    No official blender releases have a bpy module that can be imported into a python interpreter. To get a bpy module that can be imported into a normal copy of python you need to build blender as a python module yourself using custom settings. The bpy module you use within blender is part of the blender binary and only available within a running copy of blender. – sambler Dec 06 '15 at 09:23
  • I see; so this is not officially supported? This is quite depressing. Where could I find info about how to buld blender as a python module? –  Dec 06 '15 at 09:25

1 Answers1

3

Blender as a python module is only available if you build blender from source yourself, normally the bpy module is only a part of the blender binary and is not available separately with any official blender releases. At this stage I don't know of any third parties that have made a bpy module available to download.

There are several ways you can use the bpy module within blender -

  • within a running copy of blender - blender includes a python console that can be used like a normal python interpreter, it also includes a simple text editor that has the option to run the text block as a python script.

  • run the script in blender from the cli - you can tell blender to run in the background (without the gui) and to run a python script.

    blender -b --python myscript.py
    
  • it is also possible use blender as a python interpreter

    blender -b --python-console
    

By default using blender as a python interpreter will only provide access to the reduced module list that blender includes with it's distributions. You can manually install python modules into the blender installed python to have them available. It is also possible to adjust the paths that python searches for modules. If you build blender yourself there is an option to use the system python instead of a local copy, you should also be able to delete (or move) the python libraries included with blender and have it find the system installed version, be careful to use matching versions.

sambler
  • 6,917
  • 1
  • 16
  • 23
  • Thanks a lot for the explanation; I did search around and found some references to bpy; but nothing that would actually allow me to use it "standalone" decoupled from Blender itself. I will use your solution, which at this point is the only feasible. –  Dec 06 '15 at 10:35