How to run a python script in blender?

Just a humble request before you read this post. If you feel this is helpful, please consider helping me by donating using PayPal using the link below.

Click here to donate!


Many you may need to run python scripts in blender environment. So here is how you can run a python script in blender.

  1. Open a Text Editor view in Blender.
  2. Press Alt + O, or go to Text>Open Text Block and open the .py file
  3. Then simply press Run script or press Alt+p

If you want to run the script form python console, you use following,

filename = "/full/path/to/script.py"
exec(compile(open(filename).read(), filename, 'exec'))

To run a script by another script or from console, you can use followings,

import bpy
script = bpy.data.texts["script_name.py"]
exec(script.as_string())

To run the script from terminal,

$ blender filename.blend --python script.py

I hope this is helpful.  I am honored to have you on this page.

Thanks.

Get this animation : blender file 

Author: learnsharewithdp

I am a mechanical engineer, digital content creator, ,blogger, educator and excited to learn everyday.

Leave a comment