Using external IDE PyCharm for writing Blender scripts

Blender has an internal text editor to write scripts on Python language. However, this editor is much inferior to specially designed for writing code IDEs. There is no satisfactory autocomplete, comfortable syntax lighting, possibility to organize projects in Blender internal text editor – all those things that determine the speed and ease of code writing. However, it is not difficult to connect and use an external IDE for writing Blender scripts.

External IDE for scripting in Blender
External IDE for scripting in Blender

At present, there are several IDEs (Integrated Development Environment) for Python language. Each of them has some advantages and disadvantages. Let’s connect Blender with an external IDE PyCharm by the JetBrains company. This is a quite powerful environment that has all basic functions which almost completely covers all the usual requirements for such programs. Also, it has free Community version.

  1. Download and install PyCharm on your computer
    1. Download the package from the official website: PyCharm Community Edition.
    2. Install PyCharm.
  2. PyCharm requires a separate Python interpreter. It must be downloaded and installed too.
    1. Download the package from the official Python website. The best is to download and install the same version of the interpreter that Blender use.
    2. To learn Blender Python interpreter version – In the main Blender menu choose:
      1. Help – Save System Info
      2. Specify place to save the file with current Blender system information.
      3. Open the saved file and in Python section find the version number.

        Learning Blender Python version number
        Learning Blender Python version number
      4. Blender 2.77 use Python version 3.5.1
      5. Install required version of Python interpreter.
  3. Now we can create Blender script file in PyCharm:
      1. Run PyCharm
      2. Create a new project
        1. Press Create New Project in start-up screen
      3. Specify the project location and choose the interpreter:
        1. In the “Location” field specify the project location. For example D:/Blender/motion_script
        2. In the “Interpreter” field specify the Python interpreter.
    Creating PyCharm project
    Creating PyCharm project
    1. After creating project right click the project name to open its menu. Select New – Python file to create a new script file. For example name it
Creating new script file
Creating new script file

The script file is ready.

  1. To get properly Blender API auto-complete in PyCharm we need to export API description files from Blender and include them in the created project.
    1. To export Blender auto-complete description files we can use the utility pypredef_gen.
        1. We need only one file from it. This file is located in the python_api directory.
        2. Download this file and save it somewhere on your computer, for example in the root of drive D:/
        3. To execute it create a batch file ppg.cmd with the following content, replacing _BLENDER_PATH_ with the full path to Blender (eg it can be: % ProgramFiles%\blender_2.77, but be sure to write your own):

      1. Run ppg.cmd file.
      2. After ppg.cmd execution in the same place where the file is located (in our case in the root of drive D:/) will be created pypredef directory with files describing the Blender API structure. Save this directory in any convenient place.
      3. It needs to link created files to our PyCharm project. Files can be included in all PyCharm projects (once, but this case they will be used, even in projects that are not related to Blender), or you can include them to each new separate project.
          1. For a one-time connection to all projects (current and future):
            1. In the PyCharm main menu select: File – Settings
            2. Project: The name of the current project – Project Interpreter
            3. Click the gear icon in the right upper corner of the window – More
            4. Click Show Paths For The Selected Interpreter
            5. Click the green positive sign icon and add the directory with pypredef files (st. 4.1.5) to list.
        Adding Blender API autocomplit to all PyCharm projects
        Adding Blender API autocomplete to all PyCharm projects
        1. To connect files only to the current project:
          1. In the PyCharm main menu select: File – Settings
          2. Project: The name of the current project – Project Structure
          3. Click Add Content Root and add the pypredef directory (st. 4.1.5) to list.
Adding Blender API autocomplit only to current PyCahrm project
Adding Blender API autocomplete only to current PyCahrm project

After performing these steps, Blender API autocomplete will work in the PyCharm project.

Blender API autocomplit
Blender API autocomplete

Important note:

For those who have some issues with importing files for auto-complete with pypredef_gen – try to use this ready API package, which I found on the internet. Unfortunately, pypredef_gen author did not update it more than a year and it does not work correctly with Blender newer than 2.78.

  1. Open Blender
    1. Open internal Blender text editor
    2. Press New button to create a new file
    3. Write the following text, replacing _PATH_ with the PyCharm script path (st. 3.3.1.) (in our example D:/Blender/motion_script) and _FILE_NAME_ with the script file name (st. 3.4) (in our example motion_script).

Everything is ready to write scripts. You can switch to the PyCharm, write a necessary script in the created file, using all the advantages of this IDE. Then return to the Blender and just click the Run Script button to execute prepared script.

Blender file with this text can be saved in a convenient place as a template, and you can use it to write different scripts in future.

Bonus script example:

For example, type the following code to the script file created in PyCharm:

This script creates a cube, adds a facet to it, reproduce it to 20×20 cubes and randomly raises each of them by Z axis in the range from 0 to 1. The result is a stylish tech background with cubes. Just assign material, set lighting, and start rendering.

Script running result
Script running result
  • Robert Dowling

    Hi, thank you for this!
    I am having some issues when running the bat file. I’m getting and Attribute error:
    AttributError: ‘NoneType’ object has no attribute ‘keymaps’…

    This is with a clean install of Blender 2.79 and Python 3.5.3

  • Matt Down

    Thanks for guide. Works great except for bmesh.ops and bmesh.types, any idea what the fix might be for this? Thanks in advance!

    • May be some issues in pypredef_gen? Its author updated it last time more than a year ago.
      Try to use this bmesh.types
      I do not have bmesh.ops too.

      • Matt Down

        Thanks for your quick response. I will take a look in pypredef_gen and see if I can get it working.

        • If you will be successful in solving this problem, please write here your solution.

  • Jérémy Legigan

    Hello. I’ve got a problem with the bpy module. Pycharm recognizes all other modules except the bpy module. Have you got any idea where the problem can come from ?

  • Colin Basnett

    The formatting on this guide is really whack, makes it look a lot more complicated than it is. Perhaps consider removing all the nested lists.

    • Thank you for your comment! I corrected the most terrible lists, making them a little less indentation.


    Please make sure that you equally update the directory or file path : d:/ to match your exact location of as found in item 4.3. This gave me problems before I figured it out. However thanks so much.

    • Yes, you need the proper way to in your cmd-file if it differs from example. Thank you for remark!