9
$\begingroup$

I'm trying to configure pycharm so it can autocomplete blender python. When searching the web, I only found a solution to autocomplete bge. This was done using preconfigurated files though. Is there a way I can get this to work?


Debug error when running refresh_python_api.bat:

RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'compute_device_type', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'addon_filter', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'scene', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'modifier', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'property', 'default'
RNA Warning: Current value "1" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'modifier', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'name', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'modifier', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'action', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'scene', 'default'
RNA Warning: Current value "1" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'modifier', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'scene', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'type', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'modifier', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'shape', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'image', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'pose', 'default'
RNA Warning: Current value "1" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'mask', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'type', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'action', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'type', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'clip', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
RNA Warning: Current value "1" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'old_id', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'new_id', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'node_item', 'default'
RNA Warning: Current value "1" matches no enum in 'EnumProperty', 'group_select_mode', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'pose', 'default'
RNA Warning: Current value "0" matches no enum in 'EnumProperty', 'group', 'default'
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\Program Files\Blender Foundation\Blender\doc\python_api/pypredef_gen.py", line 1177, in <module>
    main() #just run it! Unconditional call makes it easier to debug Blender script in Eclipse,
  File "C:\Program Files\Blender Foundation\Blender\doc\python_api/pypredef_gen.py", line 1144, in main
    rna2predef(path_in_tmp)
  File "C:\Program Files\Blender Foundation\Blender\doc\python_api/pypredef_gen.py", line 1053, in rna2predef
    bpy2predef(BASEPATH,"Blender API main module")
  File "C:\Program Files\Blender Foundation\Blender\doc\python_api/pypredef_gen.py", line 1002, in bpy2predef
    file = open(filepath, "w")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Program Files\\Blender Foundation\\Blender\\doc\\python_api\\pypredef-tmp\\bpy.py'
Error: Not freed memory blocks: 124, total unfreed memory 0.030273 MB

Blender quit
$\endgroup$
6
$\begingroup$

I found that the script mentioned by neowitch had some shortcomings (the fact that data and context were assigned at the top of bpy.py made pycharm sad), so I made a modified version:

https://github.com/mutantbob/pycharm-blender

Unfortunately, right now it does not offer pre-dumped API stubs. You'll have to run it either from the command line, or from a text buffer inside blender. Github isn't really set up to offer pre-built packages (which is essentially what a precomputed set would be).

Also, there are a couple of techniques for getting the generated python into the namespace of your pycharm that I consider better than copying into Python's Lib folder

  1. add the python_api/pypredef folder to the Project Structure as another source root.
  2. add they python_api/pypredef folder to the interpreter's library set (a little trickier, but makes it work in all pycharm projects)
$\endgroup$
  • $\begingroup$ I'm sorry, but I do not understand where your script is better than the original... When I run your refresh_python it gives an error... $\endgroup$ – Bert VdB May 26 '17 at 19:36
  • $\begingroup$ It worked on my linux laptop. If you're using windows run it from a text buffer inside blender, or you can read the shell script to learn the command-line invocation. If there's some other sort of error, i can not troubleshoot the error without knowing what the error is. $\endgroup$ – Mutant Bob May 30 '17 at 21:26
  • $\begingroup$ When I run this script inside blender, blender crashes... $\endgroup$ – Bert VdB May 31 '17 at 8:49
  • $\begingroup$ This is the full error when I run the *.bat script: $\endgroup$ – Bert VdB May 31 '17 at 8:49
  • 2
    $\begingroup$ I'm having the same problem as @BertVdB. I downloaded the script and invoked Blender 2.78 to run it (on Windows). It works for a few seconds then fails with Error: Not freed memory blocks: 124, total unfreed memory 0.030273 MB. The last line it printed before that is updating: mathutils.py. The script did generate a bunch of Python files in a pypredef/ subdirectory but I have no idea if they're complete. $\endgroup$ – François Beaune Jul 28 '17 at 18:13
4
$\begingroup$

Answered on blenderartists in Dec 2015

  1. Download pydev-blender.zip from http://airplanes3d.net/pydev-000_e.xml

Quoted from ba:

  1. unzip into Blender folder(where blender.exe is).
  2. go into doc folder and run refresh_python_api.bat.
  3. go into doc\python_api\pypredef folder and change all extensions to .py instead of pypredef.
  4. cut or copy contents of pypredef folder to you Python's Lib folder.*

Be warned, that zip is from some time between 2011 and 2013. It's all Blender 2.5 and I cannot say if or what changes have been made since then.

*EDIT: After working with pycharm for a while, I strongly recommend Mutant Bob's method of adding the generated python file folder to either the Interpreter or the Project Structure instead of copying them to the Python Lib!

$\endgroup$
  • $\begingroup$ This doesn't work correctly for me. I configured an interpreter path to look up the pypredef folder, but PyCharm still doesn't know about bpy.props for example. I tried adding the single files instead of the folder, but they disappeared after restarting PyCharm. I just have import bpy at the top of a python module, then try to use it like bpy.props.BoolProperty(...). Any ideas? $\endgroup$ – Ray Jul 19 '16 at 19:29
  • $\begingroup$ I had the same problem when I started working with the blender interface and it is still something I haven't found a perfect solution for tbh. Some time ago I found this definition: github.com/nazodane/pydev_predef I'm using both this and the definition above in conjunction. That seems to cover everything. Download the repository, In PyCharm-installation-folder/bin locate idea.properties, open with nodepad and change idea.max.intellisense.filesize to 999999 (99999 works just fine too) Then add the predev folder to your project via Project Structure > Add Content Root $\endgroup$ – neowitch Jul 20 '16 at 14:51
  • $\begingroup$ That sounds like a better solution, but it's a shame the defs don't contain bpy.context and bpy.data =( I wish there would be just autocompletion files shipped with Blender itself... $\endgroup$ – Ray Jul 20 '16 at 16:34

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.