简体   繁体   English

Python:在Windows上运行bpy脚本

[英]Python: run bpy scripts on Windows

I have found online 2 commands that load a file and convert it in another format; 我在网上找到了2条加载文件并将其转换为另一种格式的命令。 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. 虽然这些命令需要bpy,但我无法导入。

I did install python 3.4 and the latest blender for Windows. 我确实安装了python 3.4和用于Windows的最新Blender。 Why Python can't find the bpy library? 为什么Python找不到bpy库? I am used to work with pip on unix systems, and this is my first attempt at using python on windows. 我曾经在unix系统上使用pip,这是我在Windows上使用python的第一次尝试。

In the worst case I will just use linux via VM, but since I am running on windows; 在最坏的情况下,我将仅通过VM使用linux,但是由于我在Windows上运行; I would rather find out how you work with bpy. 我宁愿找出您如何使用bpy。

UPDATE: 更新:

I did check the similar topic related to errors when importing bpy; 导入bpy时,我确实检查了与错误相关的类似主题; in that case the module is not present, while in my case I can see the module in the Blender scripts folder. 在这种情况下,该模块不存在,而在我的情况下,我可以在Blender脚本文件夹中看到该模块。

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. 我确实将脚本复制到了Python3.4文件夹中,当我现在运行import语句时,它可以看到它,但是抱怨没有_bpy模块这一事实。 Not sure if there is a python version issue or some other problem. 不确定是否存在python版本问题或其他问题。

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. Blender作为python模块 ,仅当您自己从源代码构建Blender时才可用,通常bpy模块只是Blender二进制文件的一部分,并且不能与任何正式的Blender版本单独提供。 At this stage I don't know of any third parties that have made a bpy module available to download. 在此阶段,我不知道有任何第三方提供了bpy模块供下载。

There are several ways you can use the bpy module within blender - 您可以使用几种方法在Blender中使用bpy模块-

  • 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. 在Blender的运行副本中-Blender包括一个可以像普通python解释器一样使用的python控制台,它还包括一个简单的文本编辑器,可以选择将文本块作为python脚本运行。

  • 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. 从cli在Blender中运行脚本-您可以告诉Blender在后台运行(不使用gui)并运行python脚本。

     blender -b --python myscript.py 
  • it is also possible use blender as a python interpreter 也可以将Blender用作python解释器

     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. 默认情况下,使用blender作为python解释器将仅提供对blender包含在其发行版中的简化模块列表的访问。 You can manually install python modules into the blender installed python to have them available. 您可以手动将python模块安装到安装了Blender的python中,以使它们可用。 It is also possible to adjust the paths that python searches for modules. 也可以调整python搜索模块的路径 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. 如果您自己构建Blender,则可以选择使用系统python而不是本地副本,还应该能够删除(或移动)Blender随附的python库,并找到系统安装版本,请谨慎使用匹配的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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