这里的作者在17.20-17.50点提到您将来可以使用标准Python解释器访问BPY.它已经有1年了,那么如何使用标准的python控制台访问BPY?
试验0:roundaround -solution不能与Blender中的子进程一起使用
Run Code Online (Sandbox Code Playgroud)subprocess.call(['vim', 'test.py']) # some editing of BPY -file with Vim (not working currently) subprocess.call(['python', 'test.py']) # trying to execute the python -file (not working currently)试验1:不在Blender外工作
Run Code Online (Sandbox Code Playgroud)$ cat cubes.py import bpy mylayers = [False]*20 mylayers[0] = True add_cube = bpy.ops.mesh.primitive_cube_add for index in range(0, 5): add_cube(location=(index*3, 0, 0), layers=mylayers) $ python cubes.py Traceback (most recent call last): File "cubes.py", line 1, in <module> import bpy ImportError: No module named bpy
Tob*_*ler 15
根据这些说明:
获取blender源代码:
cd ~/src # or what you prefer
git clone http://git.blender.org/blender.git
cd blender
git submodule update --init --recursive
git submodule foreach git checkout master
git submodule foreach git pull --rebase origin master
Run Code Online (Sandbox Code Playgroud)
注意依赖关系,如果需要,请参见此处*并通过bpy目标进行编译:
cd ~/src/blender
make bpy
Run Code Online (Sandbox Code Playgroud)
(重新)如果像错误运行后者作为根file INSTALL cannot set permissions on [...]发生
你的python 3现在应该可以了import bpy.
*对于Debian-ish系统运行
sudo apt-get install subversion build-essential gettext \
libxi-dev libsndfile1-dev \
libpng12-dev libjpeg-dev libfftw3-dev \
libopenexr-dev libopenjpeg-dev \
libopenal-dev libalut-dev libvorbis-dev \
libglu1-mesa-dev libsdl1.2-dev libfreetype6-dev \
libtiff4-dev libavdevice-dev \
libavformat-dev libavutil-dev libavcodec-dev libjack-dev \
libswscale-dev libx264-dev libmp3lame-dev python3.2-dev \
libspnav-dev libtheora-dev libjack-dev libglew1.6-dev
Run Code Online (Sandbox Code Playgroud)
如果这仍然相关,你可以像这样在blender的上下文中运行一个脚本(-b使它无头,所以你可以在没有X11的渲染服务器上运行它):
blender -b -P script.py
Run Code Online (Sandbox Code Playgroud)
有关更多选项见blender --help.
如果你想将blender连接到一个IPython控制台,那么你可以通过python与blender进行交互,你可以使用我刚写的这个脚本:https://github.com/panzi/blender_ipython
启动笔记本:
./blender_ipython.py notebook
Run Code Online (Sandbox Code Playgroud)
启动Qt控制台:
./blender_ipython.py qtconsole
Run Code Online (Sandbox Code Playgroud)
在您在那段时间发布的视频链接中,没有提到使用标准 python 解释器运行独立的搅拌机 python 脚本。您在视频中看到的是他们为 Blender 内置的解释器打开了交互式控制台。
Blender 需要它自己的捆绑 python 环境,如果您要尝试使用标准 python 解释器运行脚本,则必须设置环境以包含 Blender 包中的所有包。虽然看起来它甚至可能不可能,因为我认为 Blender 的 python 被修改了。
Blender 可执行文件似乎允许您通过以下方式运行 python 脚本:
/path/to/blender -P cubes.py
您还可以通过以下方式从 bash shell 启动交互式控制台:
/path/to/blender --python-console