View RSS Feed

Steve Baer

Configuring Pydev for Rhino.Python

Rate this Entry

NOTE: This article is specific to getting Pydev to work on Windows. I've had problems getting the ironpython interpreter to work inside Pydev on Mac. Hopefully this will inspire someone to hack away at the Mac version of Pydev and figure out what it takes to make it work for Rhino.Python.

What's Pydev?
The folks at Pydev can probably do a much better job of explaining their product (http://pydev.org/index.html). In short, Pydev is a popular Python script editor (and debugger). Several python scripters who are familiar with Pydev have asked about how to configure it for editing Rhino.Python scripts.

Rhino for windows already comes with a built-in python editor, but I can understand that people will want to use a different editor for many reasons (they're familiar with it or it has features that are missing in the Rhino editor.) Here's the steps I took to get this to work on my Windows 7 computer.

A. Install Pydev - Here's a page I used to get everything set up for Pydev http://pydev.org/manual_101_root.html
If you've already installed Pydev on your computer, you can skip this section.
  1. Download eclipse (http://www.eclipse.org/downloads/).
    I downloaded Eclipse Classic 3.6.1 (~170MB) 32bit version for windows.
    I downloaded the 32 bit version because I haven't installed the 64 bit version of java on my computer and eclipse requires java to run.
    File name is eclipse-SDK-3.6.1-win32.zip
  2. Unzip file and double click on the eclipse.exe to start eclipse
  3. go to help->Install Software and type the following URL into the Work with text box
    http://pydev.org/updates
  4. You should get checkboxes for available pydev plug-ins. Check the Pydev item and click next, then finish
  5. This installs the pydev plug-in for eclipse


B. Install IronPython Executables
Rhino.Python uses Microsoft's IronPython engine to process python scripts. Pydev is going to need to use this same engine in order to get things like auto-complete to work.
  1. Go to codeplex and Install "IronPython 2.6.2 for .NET 4.0" http://ironpython.codeplex.com/releases/view/41236
    The download link is in the upper right corner of the web page
  2. This installs the command IronPython command line interpreter which is needed by PyDev


C. Configure Pydev
  1. Start eclipse.exe
  2. Select Preferences from the Window menu
  3. Expand the Pydev node in the preferences tree and select "Interpreter - Iron Python"
  4. Click the "New..." button which brings up a "Select Interpreter" dialog
  5. Click the "Browse..." button and select ipy.exe which on my computer happens to be located at
    C:\Program Files (x86)\IronPython 2.6\ipy.exe
  6. Click OK and then another OK to accept the default folders added to the SYSTEM pythonpath
  7. Add the lib folder that contains the rhinoscript package to the system python path in order for Pydev to recognize any of the rhinoscript functions
    On the Libraries tab click click the "New Folder" button and pick the directory where the rhinoscript package is located. You can find this folder location by looking at the Paths in the built-in Rhino.Python editor. On my computer this directory is located at
    C:\Users\a-steve\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib
  8. Add RhinoCommon as a "Forced Builtin". In order to do this we need to create a directory that will be on the python path. I created a new folder in the eclipse directory called pydevrhino and added it to the python path by clicking the "New Folder" button on the Libraries tab and selecting this new folder. On my computer, this folder is located at
    C:\Users\a-steve\Desktop\eclipse-SDK-3.5.2-win32\pydevrhino
  9. Pydev has a limitation where it can only read .NET assemblies with a root namespace the same as the dll. We want to get at all of the classes inside of RhinoCommon.DLL, but the root namespace in this DLL is Rhino. Go to the Rhino5 system folder (where the main executable is located) and copy RhinoCommon.dll (and RhinoCommon.xml) to the new folder that you created in the previous step. In the new folder, rename these files to Rhino.dll and Rhino.xml (DON'T CHANGE THE FILES IN THE RHINO SYSTEM DIRECTORY).
  10. Go to the "Forced Builtins" tab, click New... button and type in "Rhino".

D. Start Using Pydev
Good luck! Here's what I get for autocomplete on Rhino and rhinoscript classes/functions

Updated 01-06-2011 at 10:43 PM by Steve Baer

Tags: None Add / Edit Tags
Categories
RhinoPython

Comments

  1. paulnic -
    paulnic's Avatar
    Hi Steve,

    Many thanks for posting these notes. I may be making a mistake in following them, but I can't get past the following error message:

    No module named Rhino.ApplicationSettings.AppearanceSettings

    Would you be able to clarify?

    thanks, paul
  2. Steve Baer -
    Steve Baer's Avatar
    Hi Paul,
    Sounds like something is not quite working. When do you get this error message?
  3. Steve Baer -
    Steve Baer's Avatar
    Hi Paul,
    Sounds like something is not quite working. When do you get this error message?
  4. hliemke -
    hliemke's Avatar
    Hi Steve,

    is it possible to run a Rhino Python script from Pydev? I always get
    ImportError: No module named RhinoPython.Host

    Thanks, hans
  5. rbeson -
    rbeson's Avatar
    Hi Hliemke

    I think it might be something to do with setting up the Eclipse Application Launcher correctly:
    http://help.eclipse.org/helios/index.jsp

    I haven't had time to work it out, but would be good to know if anyone else has.

    Cheers,
    Rob
  6. hliemke -
    hliemke's Avatar
    Hi Rob,

    thanks for the info.

    hans
  7. BenjaminGolder -
    BenjaminGolder's Avatar
    I'm doing all this, but I'm using IronPython 2.6 for .NET 4.0 instead of IronPython 2.6 for .NET 2.0 as my IronPython engine.
    Am I correct to assume that this difference is not a problem?
  8. BenjaminGolder -
    BenjaminGolder's Avatar
    One last step that should be obvious to most people:
    after adding "Rhino" to "Forced Builtins", restart Eclipse. If you don't restart you won't see the auto-complete.
  9. Dimitry -
    Dimitry's Avatar
    Dear All,

    I got the same error as paulnic
    ImportError: No module named Rhino

    after running
    import Rhino

    I am sure, that I did all of the Steve steps(see the pictures),
    but unfortunately something doesn't work.
    Could somebody of you guys take a look in the images, maybe I did a mistake somewhere?


    Except this mistake the library is working correctly
    for example
    import Rhino as rh
    I got the hole list with all attributes

    Thankx in advise
    Dimitry
  10. TijlU -
    TijlU's Avatar
    Hans,

    Did you manage to solve your problem with No module named RhinoPython.Host??
    if so, how did you do that?

    Thanks,

    Tijl
  11. TijlU -
    TijlU's Avatar
    Dimitry,
    i get the same error, but i can't do the library either..
    Even there it shows up with an error message, no module named rhino..

    Strange! Hope someone can help!
    Tijl
  12. Dimitry -
    Dimitry's Avatar
    Hey Tijl,

    I was trying yesterday with different ironpython 2.6 .net2, ironpython 2.6 .net4 (also ironpython 2.7(that doesn’t worked at all)) but got the same error. I’ll try during the new year holyday again, hope to get positive result.
    Do somebody know, why is impossible to add pictures from harddisk here?

    Best
    Dimitry
  13. TijlU -
    TijlU's Avatar
    Hi Dimity,

    I have installed everything anew, but without any luck. Did install eclipse again(and followed the steps of Steve) and even re-installed Rhino (both 32bit instead of 64). So hopefully someone can help us??

    Good luck.

    Tijl
  14. robincwillis -
    robincwillis's Avatar
    I think most of the errors people are talking about are from running scripts from pydev. Is this meant to actually give you the ability to run a script from pydev? Or just get the auto completion. I think the latter right?
  15. bluelotus0107 -
    bluelotus0107's Avatar
    yeah,the latter!Did anyone slove the problem?
  16. reisod -
    reisod's Avatar
    OSX PyDev Interpreter

    I've been working on trying to get eclipse up and running on OSX with PyDev. I'm also stuck at the interpreter but I thought I'd list a bit of where I'm at, in case others are working on it too - it might prove helpful.

    From what I understand, on OSX, the IronPython interpreter has to be called through Mono, and cannot be called directly. PyDev doesn't currently support Mono, which means that a straight up approach might be stalled. This issue was discussed on the PyDev forums here:
    http://sourceforge.net/projects/pyde.../topic/3418511

    There was a PyDev feature request logged for this in November 2009, but seems to have been thus far overlooked:
    http://sourceforge.net/tracker/?func...96&atid=577332

    I'm going to keep banging my head against this wall for a bit, as it would be really nice to work inside of a single IDE for Processing, Rhino, and Maya - but until then, at least Komodo is running.
  17. Rodrigo_Medina -
    Rodrigo_Medina's Avatar
    Hello so I think I manage to make PyDev to work Properly in Ecplipse following Steve´s steps at least the auto complete functions and stuff I guess , my question would be the same is there a way to run scripts from ecplise to test them on rhino or the only way to do it is to save the .py file and load it from the rhino built in editor ??


    Thanks
  18. robertjasoncross -
    robertjasoncross's Avatar
    I am not getting any auto complete success. I am using Eclipse 3.7.1 and the latest PyDev. I am going to stick to the Python editor in Rhino for now. It would be very nice to get the same response in an IDE. Thanks for getting things going in that direction.
  19. buzz lightyear -
    buzz lightyear's Avatar
    Hi guys,

    I am trying to configure PyDev for Rhino.Python for Mac. I saw reisod was trying, but his post is from 08.2011. Did anybody have any luck? Is there any guidance I could follow?

    Thanks a lot in advance