Using PyCharm for editing RhinoPython

PyCharm from JetBrains is one of the most powerful IDE for python, and i don’t think Rhino development team need to put a lot of recourse to make EditPythonScript as good as PyCharm or other IDEs.

So i try to use PyCharm for editing python for rhino, but i don’t know how to make PyCharm understand the RhinoPython module structure. (i.e. after i type “rs”, no hints of method appear, and “import rhinoscriptsyntax as rs” is shown with error)

Do anyone try to use PyCharm for editing before? If so, can you share how you make PyCharm understand the modules of RhinoPython?

Thx!!

Hi James,

I did not try that specific IDE, but usually you need to find the way for it to find your rhinoscriptsyntax.py file. You usually do that by adding the folder:
%appdata%\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib
to the Python PATH used by the “Intellisense” feature of that IDE.

I hope this helps,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Has anyone got PyCharm to work with Rhino. I am having trouble importing the Rhino Python Libraries.

Hi,

To add the path to the Rhino Python lib that Giulio mentions above in PyCharm

  • select “Settings…” from the “File” menu.
  • click on Project Interpreter / Python Interpreters on the left.
  • make sure IronPython is your selected interpreter (top right).
  • click the “Paths” tab (bottom right)
  • add the path mentioned by Giulio. If the dialog doesn’t let you browse there, you can cut and paste the path from explorer.

Hope that helps
Cheers

I’ve just tested the method proposed by Alain, and it will work great for import rhinoscriptsyntax, which is already helpful. It will not work with import Rhino (RhinoCommon.dll) as it stands. The reason is that there are a couple of quirks in that editor to make IronPython assembly load, and even then not everything will be perfect, but still much better than nothing. If you wish to use Rhino there, do this:

  • add also the path to RhinoCommon.dll (32-bit or not according to the IPy interpreter that you use) to the list of paths (same as in Alain’s answer above). On my system, this is:
    C:\Program Files (x86)\Rhinoceros 5\System\
  • add these few lines of code to your script:
import clr
clr.AddReference("RhinoCommon")
import Rhino
import Rhino.Geometry

  • place the caret (click on) the word “Rhino” besides import
  • press Alt+Enter
  • select “Create skeleton implementation for binary import” (or very similar)
    Now repeat this for all missing imports. You can also use my skeletons and place them in the ‘binary skeletons’ folder. I’ve pre-exported all RhinoCommon namespaces as of today for you in this zip.

Rhino.zip (299.4 KB)

This is what you get:

I hope this might also be helpful,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Do we have to use IronPython as our interpreter? Can we use Anaconda’s python.exe?

IronPython is the interpreter that Rhino uses.

I managed to get all the hints to the methods to appear but when I run my debugger I get an error. See screenshot.


Error Message:
“C:\Program Files (x86)\IronPython 2.7\ipy.exe” C:/Users/marafi/PycharmProjects/RhinoTest/Test.py
Traceback (most recent call last):
File “C:/Users/marafi/PycharmProjects/RhinoTest/Test.py”, line 3, in
File “C:\Users\marafi\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscriptsyntax.py”, line 2, in
File “C:\Users\marafi\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript_init_.py”, line 8, in
File “C:\Users\marafi\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\application.py”, line 1, in
File “C:\Users\marafi\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\scriptcontext.py”, line 2, in
AttributeError: ‘LightException’ object has no attribute ‘Host’

Of course. You need a running instance of Rhino to execute Rhinoscripts. You might be able to run remote debugging in Rhino, though. With this method.

I hope this helps,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

And I believe only the Professional edition of PyCharm supports remote debugging.

I’m still getting this error trying to set up Rhinoscripting with Eclipse + Pydev:
AttributeError: ‘LightException’ object has no attribute ‘Host’

I have Rhino 32-bit up when running the script in Eclipse, but still getting the error.

Basically, I have Exlipse (JUNO) + Pydev + IronPython set up with all the right paths and the builtin as Steve suggested in his tutorial: https://stevebaer.wordpress.com/2010/06/12/configuring-pydev-for-rhino-python/
After set up, I create a new Pydev project and a new module within where I paste in a piece of python code I’ve successfully ran in Rhino’s built-in Python editor. An instance of Rhino 32-bit is also open at the same time. But still getting the error.

Any ideas what I’m doing wrong?

Hi.
You can edit the script in PyCharm or PyDev but you can’t execute it directly from there. The script has to run in the context of Rhino. You can setup your IDE for remote debugging to step into your code like described above or in my reply to your other post.

Hi @Alain,

I want to use Pycharm Community edition to write and edit python code I write for GhPython components in grasshopper. I stumbled upon this thread during my search for possible solutions. I want to follow the steps you mentioned. However, in the list of project interpreters I don’t see IronPython. I tried to use it from my local drive, but coould not successfullly locate a .exe file for IronPython. I could only locate a .dll file.

can you please help?
Thanks,
Devang

@Devang_Chauhan it would be better to start a new topic. This one was about _EditPythonScript. If you want to reply, please choose the link icon -> then New Topic . If your goal is just writing, then it would be easy to just add a File Reader, and input the content into the ‘Code’ input of a GhPython component.

Hi all,
I have started using Pycharm Community Edition to edit my python scripts for Rhino and then executing them as normal in Rhino 5 using EditPythonScript or RunPythonScript.
I forked this repo https://github.com/gtalarico/ironpython-stubs and imported it into Pycharm (VCS - checkout - github) to get ‘stub’ files giving the autocomplete and quicklook <ctrl + Q> information for rhinoscriptsyntax, Rhino, clr, scriptcontext, etc. Please note that the currently included stubs are for Rhino 5 and include only documentation, but no code so you can’t execute them. I havent tried using it to generate my own stubs but it should be possible to do this for Rhino 6.
I then started a new project in Pycharm, went to ‘project structure’ in settings and pointed to the /release/stubs folder as a ‘Content Root’. This lets Pycharm know where to look for docstrings
Finally under Inspections I checked Python 2.7 and unchecked all other versions of Python.
Seems to be working well so far… Any advice / comments welcome on this if you have another way of doing thing.

1 Like

alternatively…

1 Like