Eclipse for Python and Robots Setup
This document details how to set up Eclipse to work with Python 2.5 and the r-one robots.
NOTE: This is for advanced users only. We are not supporting using the r-one robots with Eclipse.
First, follow the instructions in the Python setup document and install Python 2.5.4 and pyserial.
Install Eclipse and PyDev
-
Go to the Eclipse web site (www.eclipse.org) and download Eclipse Indigo 32-bit.
-
Start Eclipse and set up a workspace
-
Click "Help" from the menu and then "Install New Software..."
-
Click "Add..." in the top right
-
Put "PyDev: Python for Eclipse" in the Name box and "http://pydev.org/updates" into the Location box.
-
Check ONLY the PyDev box, not PyDev MyIyn Integration
-
Click "Next" and "OK"
-
Click "I accept the terms of the license agreement" then "Finish".
-
When the Selection Needed box appears, check the Aptana Pydev; Pydev; Aptana box and click "OK"
NOTE: if you don not check the box, PyDev will seem to install by will not and you will need to uninstall and reinstall PyDev.
-
If a security warning appears, click "OK" and ensure the correct items are selected and click yes
-
Now restart Eclipse. You may see a "Subclipse usage" dialog, just uncheck the box and continue
Configure PyDev
-
Click "Window" from the toolbar menu, then "Preferences"
-
Expand PyDev from the options on the left
-
Click on "Interpreter-Python"
-
Click "New" in the top right corner
-
In the Interpreter box type "Python 2.5" and in the Interpreter Executable type "C:\Python25\python.exe"
NOTE: The Interpreter Executable line depends on where you put your Python 2.5 executable. This is the location that our Python setup document says to put it. If you placed it somewhere else, use the browse button to locate the python.exe file.
-
In the resulting "Selection Needed" window, click "OK"
-
Now click on "Interactive Console" under the PyDev menu in "Preferences"
-
Add the following into "Initial interpreter commands" making sure to leave anything that is already there untouched.
import os
base_path, _ = os.path.split(sys.executable)
cwd_path = [path for path in sys.path if base_path not in path and "org.python.pydev" not in path and "python25.zip" not in path]
if len(cwd_path) == 1:
os.chdir(cwd_path[0])
else:
#choose shortest path length
os.chdir(sorted(cwd_path, key=len)[0])
NOTE: You must leave two blank lines (NO WHITESPACE [delete tabs and spaces]) for it to exit the else: correctly
Open PyDev Perspective
-
Click "Window" from the toolbar menu
-
Go to "Open Perspective" then select "Other"
-
Select PyDev from the options
-
click "OK"
Setup Project
-
Select "File" --> "New" --> "PyDev Project"
-
Name the project (eg. engi128)
-
Set "Grammar Version" to 2.5
-
Set Interpreter to "Python 2.5"
-
Click "Finish"
-
Right click on your new project and go to "Properties" (at the bottom of the menu)
-
Click on "PyDev - PYTHONPATH" then "External Libraries" from the tabs
-
Click "Add Source Folder", go to C: then Python25 then select the rone folder
-
Hit "OK"
-
Hit "OK" in he Properties window
Creating Files
-
Expand the project folder
-
Right-click on the "src" folder
-
From the resulting menu select "New" then "File"
-
Give it a name and click "Finish"
NOTE: Be sure to add .py after the file name
NOTE: Be sure to put the files in the "src" folder not just the project folder. Otherwise the Console will not be able to find them
Open Interactive Console
-
With the cursor within a file (in the project whose files you want to run on the robot).
-
Press "Control+Alt+Enter".
-
Click "OK".
NOTE: The option initially selected is the correct one. This will use the PYTHONPATH that you set up earlier.
-
Select Python 2.5 as the interpreter.
NOTE: Python will try and run the file, but will fail. This is fine.
-
Once the console window is open, you can terminate it with the red square in the bar above the console.
-
These steps are only necessary to open the console window for the first time. Once it is open, there is a button along the bar above the console that looks like an empty window with a + sign on it and select PyDev Console from the drop-down menu.