6
$\begingroup$

Is there any way to interface with blender using IPython in blender 2.68? I have tried many many options over the past couple of days and none of them have worked for me...

The best option for me would be if I could use IPython in the terminal I initiated blender with.

I have tried using IPython.embed with no success, and I also have tried this, but I can't get it to work with blender 2.68a.

Perhaps there is a way to start an instance of blender from within an IPython session?

$\endgroup$
1
  • $\begingroup$ I don't know much about this, but from what I can tell, blender --python-console does what you want. $\endgroup$
    – gandalf3
    Commented Sep 16, 2013 at 23:02

3 Answers 3

4
$\begingroup$

Yes, simply run this in a text editor

import IPython
IPython.embed()

it's even in blenders official documentation.

Note:

This will lock Blenders UI and prevent any redraws or user input while the console runs. You can start IPython in the terminal, execute some commands, then Ctrl+D, to exit the IPython and use Blender again.

There is no convenient way to avoid this.

$\endgroup$
9
  • $\begingroup$ OK, I've tried running a script containing this at startup, but I get "RuntimeError: input(): lost sys.stdin" $\endgroup$
    – user1276
    Commented Sep 16, 2013 at 3:28
  • $\begingroup$ @user1276, define "running a script containing this at startup", I tried saving these 2 lines in a script, then running: blender --python test_ipython.py and ipython gave me a prompt in the terminal I started blender from. $\endgroup$
    – ideasman42
    Commented Sep 16, 2013 at 3:41
  • $\begingroup$ Yes, this is the command I tried exactly, except when I tried it with these two lines only I received "ImportError: No module named IPython". To solve this, I have three lines appending my local python site-packages to the blender python sys.path. I also included the lines mentioned in the documentation you linked to. $\endgroup$
    – user1276
    Commented Sep 16, 2013 at 4:42
  • $\begingroup$ I tried it without the other lines from the documentation and am given a prompt, but now blender runs with a completely blank screen... When I ctrl-D out of ipython, blender loads the gui into the window... Any ideas, ideasman? :) $\endgroup$
    – user1276
    Commented Sep 16, 2013 at 4:43
  • $\begingroup$ @user1276 "without the other lines from the documentation", Please try to be specific or it becomes hard to provide useful feedback. $\endgroup$
    – ideasman42
    Commented Sep 16, 2013 at 4:49
7
$\begingroup$

For anyone coming upon this question in 2020, I had a similar want and wanted to use Blender from a Jupyter Notebook.

I made a Jupyter Kernel to do this for Blender 2.8 here. It uses asyncio so the Blender UI is not locked when using the kernel.

$\endgroup$
3
  • $\begingroup$ Brilliant. Going to try set it up this weekend :) $\endgroup$
    – satishgoda
    Commented Apr 4, 2020 at 4:13
  • $\begingroup$ We created a sample notebook available here, and there is an installer for this blender kernel here. Have fun! $\endgroup$
    – minus one
    Commented Jan 21, 2021 at 12:11
  • $\begingroup$ See also link $\endgroup$
    – minus one
    Commented Jan 21, 2021 at 12:11
0
$\begingroup$

Start Blender with a threading that run IPython.embed()

blender --python-expr '__import__("threading").Timer(0, __import__("IPython").embed).start()'

# It won't lock Blender UI.
# Have fun with IPython in blender!

If not install IPython:

# Get pip: equl to /blender-path/2.xx/python/bin/python3.7m -m ensurepip
blender -b --python-expr "__import__('ensurepip')._bootstrap()" 

# Update pip toolchain
blender -b --python-expr "__import__('pip._internal')._internal.main(['install', '-U', 'pip', 'setuptools', 'wheel'])"

# pip install IPython (or any package)
blender -b --python-expr "__import__('pip._internal')._internal.main(['install', 'IPython'])"
```
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .