When I press "run script" with a python script in the Text Editor, it runs, but seems to spawn some new invisible python interpreter. I'd like it to run in the Python Console that I already have open. Is there a way to do this?

As it stands now, I'm copying and pasting from the Editor to the Console, which sure is tedious.

  • $\begingroup$ blenderartists.org/forum/… There may be some more recent versions, and IIRC @zeffii has something similar too. $\endgroup$
    – batFINGER
    Apr 11, 2016 at 14:41
  • $\begingroup$ Another addon. Note, that the blender python console uses InteractiveConsole. You might have a look at scripts/modules/console_python.py. $\endgroup$ Apr 12, 2016 at 8:46

3 Answers 3


In Blender 2.80 and higher, you can use as_module().

Blender Python Console module example

In the above example, an unsaved text editor shows this code:

def myTestFunc():
    print('This is my test function, running')

print('This is my test module, running')

Then, in the Blender Python console on the left, you can import this:

myModule = bpy.data.texts[0].as_module()

Note that since this is my only text file, I've used texts[0] to reference it. If you had multiple, you would reference by name, such as texts["Text"] or similar.

Note that anytime the source code changes, you will have to re-run the as_module() command again to pick up the changes.

Finally, I can call functions from the module I imported, like so:


This uses the variable name that was assigned by the as_module() line, and looks for a named function within that module to call.

  • $\begingroup$ oh I love you.. a one-liner and so simple.. $\endgroup$
    – juggler
    Apr 25 at 4:02

In the text editor, make sure that the code you want to run is callable (f.e. make it a function). Name the text datablock something.py). Now you can use import something in the console, and call something.yourfunc() on it.

  • $\begingroup$ Sadly, this appears not to work anymore in Blender 2.80. $\endgroup$
    – emackey
    Dec 3, 2019 at 21:43
  • $\begingroup$ It appears that someone wrote a new answer about this ;-) Thanks @emackey $\endgroup$
    – dr. Sybren
    Dec 4, 2019 at 9:31

In Blender go to Window and select toggle system console. Do this after "run script"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.