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

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

Trial 0: roundaround development does not work with a 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: does not work outside of 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 
+9
source share
7 answers

Based on these instructions :

Get the source code of the 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 

Take care of the dependencies, see, for example, here if necessary * and compile using the bpy target:

 cd ~/src/blender make bpy 

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

Your python 3 should now be able to import bpy .


* For Debian-ish systems

 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 
+13
source

In case this is still relevant, you can run the script in a blender context like this ( -b makes it headless, so you can run it on the render server without X11):

 blender -b -P script.py 

See blender --help more options.

If you want to connect the blender to the IPython console so that you can interact with the blender via python, you can use this script that I just wrote: https://github.com/panzi/blender_ipython

Launch your laptop:

 ./blender_ipython.py notebook 

Launch the Qt console:

 ./blender_ipython.py qtconsole 
+8
source

I use eclipse for development in a blender. I found a good starting point for http://airplanes3d.net/pydev-000_e.xml

+3
source

This article explains how to create blender as a python module.

http://wiki.blender.org/index.php/User%3aIdeasman42/BlenderAsPyModule

It doesn't seem like this method will associate an external python session with a regular blender process, but rather starts blender inside the python process.

+1
source

In the video link published during this time segment, there is no mention of starting a standalone blender python script using a standard python interpreter. What you see in the video is pulling out the interactive console for the interpreter built into Blender.

Blender requires its own associated python environment, and if you try to run the script using the standard python interpreter, you will need to configure the environment to include all packages from the blender package. Although it seems like it's probably not even possible, since I think Python Blender has changed.

The blender executable seems to allow you to run a python script via:
/path/to/blender -P cubes.py

You can also start the interactive console from the bash shell via:
/path/to/blender --python-console

0
source

I am new to programming, but found an easy workaround, I used the command line for the terminal using os. My program looked something like this.

 import os os.system("cd /home/") 

(i.e. where is my blender)

and then i used the terminal command just like i used cd.

https://docs.blender.org/manual/en/dev/render/workflows/command_line.html

0
source

Someone created an API stub generator. He even accepted the generated bpy on Github for Blender version 2.78, 2.79, 2.80. You should only write code in the IDE, for example, PyCharm. There is a document too.

https://github.com/nutti/fake-bpy-module/tree/master/premade_modules/2.79

Here is a website with installation instructions if Nutti doc is somewhat short.

https://b3d.interplanety.org/en/using-external-ide-pycharm-for-writing-blender-scripts/

To run the code, you will need to use Blender Python, as already mentioned in other answers.

 blender -b -P script.py 

Sorry, the link is just the answer.

0
source

All Articles