Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access BPY in standard python console? BPY is the Blender-python -thing

Tags:

python

blender

The author here in point 17.20-17.50 mentions that you can access BPY with the standard Python interpreter in the future. It is already 1 year old so how can I access the BPY with the standard python console?

Trial 0: roundaround -solution not working with subprocess inside Blender

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)

Trial 1: not working outside Blender

$ 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
like image 482
hhh Avatar asked Jun 10 '12 21:06

hhh


People also ask

How do I open the Python console in Blender?

Accessing Built-in Python ConsoleBy pressing Shift-F4 in any Blender Editor type (3D View, Timeline etc.,) you can change it to a Console Editor. From the screenshot above, you will notice that apart from the usual hot keys that are used to navigate, by pressing Ctrl-Spacebar you can enable Auto-complete feature.

What is Blender Bpy?

props) This module defines properties to extend Blender's internal data. The result of these functions is used to assign properties to classes registered with Blender and can't be used directly. Note.

Which Python version uses Blender?

The Blender Python API is based on Python 3. It is integrated deeply, used for writing add-ons, generating user interface layouts, and import and export of many file formats.


1 Answers

Based on these instructions:

Obtain the blender source code:

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

Take care of the dependencies, see e.g. here if necessary* and compile via the bpy target:

cd ~/src/blender
make bpy

(re)run the latter as root if errors like file INSTALL cannot set permissions on [...] occur

Your python 3 should now be able to import bpy.


* For Debian-ish systems run

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
like image 173
Tobias Kienzler Avatar answered Sep 22 '22 11:09

Tobias Kienzler