6

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?

J Sargent
  • 19,269
  • 9
  • 79
  • 131
user1276
  • 251
  • 1
  • 3
  • 7
  • I don't know much about this, but from what I can tell, blender --python-console does what you want. – gandalf3 Sep 16 '13 at 23:02

3 Answers3

7

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.

cameronfr
  • 71
  • 1
  • 2
4

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.

ideasman42
  • 47,387
  • 10
  • 141
  • 223
  • OK, I've tried running a script containing this at startup, but I get "RuntimeError: input(): lost sys.stdin" – user1276 Sep 16 '13 at 03:28
  • @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. – ideasman42 Sep 16 '13 at 03:41
  • 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. – user1276 Sep 16 '13 at 04:42
  • 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? :) – user1276 Sep 16 '13 at 04:43
  • @user1276 "without the other lines from the documentation", Please try to be specific or it becomes hard to provide useful feedback. – ideasman42 Sep 16 '13 at 04:49
  • Quite sorry, without these: import code \n namespace = globals().copy() \n namespace.update(locals()) \n code.interact(local=namespace) – user1276 Sep 16 '13 at 04:52
  • When I run in debug mode, here are the two debug logs printed to the terminal between exiting ipython and the blender gui loading:
    recalcob Cube  
    recalcdata Cube
    
    – user1276 Sep 16 '13 at 05:10
  • Not sure why this would fail: suggest to, install fresh blender, backup / remove your user preferences. Remove the "python" directory in the fresh blender install (forces use of system python), then try running blender from a console and running this in blenders text editor import IPython; IPython.embed(). Troubleshooting this stuff remotely is tricky but think this has the greatest chance of working. – ideasman42 Sep 16 '13 at 22:48
  • OK, thank you so much ideasman42! I really appreciate all your help on this. I will mark this question as closed because you have thoroughly answered the solution that will likely work for most people. I have started a new question with the specific details of my problem, and I will proceed in the manner that you have suggested. – user1276 Sep 16 '13 at 22:52
0

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'])" ```

Yang
  • 361
  • 4
  • 6