简体   繁体   中英

Python: run bpy scripts on Windows

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM