Configuring Pydev for Rhino.Python
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.
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.
- 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
- Unzip file and double click on the eclipse.exe to start eclipse
- go to help->Install Software and type the following URL into the Work with text box
- You should get checkboxes for available pydev plug-ins. Check the Pydev item and click next, then finish
- 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.
- 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
- This installs the command IronPython command line interpreter which is needed by PyDev
C. Configure Pydev
- Start eclipse.exe
- Select Preferences from the Window menu
- Expand the Pydev node in the preferences tree and select “Interpreter – Iron Python”
- Click the “New…” button which brings up a “Select Interpreter” dialog
- 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
- Click OK and then another OK to accept the default folders added to the SYSTEM pythonpath
- 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
- 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
- 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).
- Go to the “Forced Builtins” tab, click New… button and type in “Rhino”.
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
D. Start Using Pydev