Top Banner
PyDev: Developing Python code in Eclipse presented to the Python Interest Group Pete R. Jemian, BCDA 401/B2100 2011-03-16 ICMS Content ID: APS_1419152 http://www.rovio.com
45

PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Jul 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

PyDev:Developing Python code in Eclipse

presented to the Python Interest Group

Pete R. Jemian, BCDA

401/B2100

2011-03-16

ICMS Content ID: APS_1419152

http://www.rovio.com

Page 2: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Abstract

Aptana PyDev (http://pydev.org) is a Python IDE for Eclipse which may be used in

Python, Jython, and IronPython development. It can be used anywhere that Eclipse

runs (including Windows, Mac, Linux). Features include syntax highlighting, code

completion, source code debugging with breakpoints and inspection of variables, and

refactoring.

Note that Python must be installed separately. It is possible to configure PyDev to use

a specific Python if more than one Python is installed.

This presentation will focus on how to install, configure PyDev for

routine use including systems with more than one Python installation.

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

2

Page 3: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Topics

� Installation

– Python

– Java

– Eclipse

– PyDev

� Configuration

– Setting up Python

� Routine Use

– Workspace

– Project

– Package

– Module

– Debugger

� Systems with more than one Python

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

3

Page 4: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Python Distributions(various distributions add extra packages)

� Python

– http://python.org/download/

� Enthought Python Distribution (Win, Mac, Linux)

– http://www.enthought.com/products/epd.php

� Python X,Y (Win, Linux)

– http://www.pythonxy.com/

� Active State Python, Community Edition (Win, Mac, Linux)

– http://www.activestate.com/activepython

� Linux package installer (Linux)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

4

Note:

Install Python in the

default location unless

you know better

Page 5: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Eclipse needs Java: http://java.oracle.comclick on “Java SE”

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

5

Page 6: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Select the Java Standard Edition (Java SE), Development Kit (JDK)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

6

Page 7: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Start the download, then install it in the default place

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

7

Page 8: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Downloading Eclipse: http://eclipse.orgClick on “Downloads”

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

8

Page 9: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Pick a version: “Classic” provides many tools.You can always edit/remove other parts later

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

9

Page 10: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Downloads from a mirror

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

10

Page 11: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Unzip the eclipse download anywhere that is convenient

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

11

Note:

Here, the ZIP file is on the desktop and extracted to the desktop

Page 12: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

start the eclipse executable(look in <extracted_folder>/eclipse/)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

12

Page 13: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Welcome to eclipse

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

13

Page 14: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Installing PyDev: http://pydev.org/updates/(this URL is an eclipse update site – use eclipse to get it)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

14

Page 15: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Select PyDev

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

15

Note:

click [Next] and click through, including License Agreement and Certificate,

Then, restart eclipse as requested

Page 16: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Installation is complete, take a break

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

16

Page 17: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Configure PyDev for the Python Interpreter

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

17

Page 18: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Arrive at the empty workbench(progressing to configure PyDev for Python interpreter …)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

18

Page 19: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

New Python Project(… still progressing to configure PyDev for Python interpreter …)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

19

Note:

There are other ways to get to the Properties dialog to configure PyDev for

the Python interpreter. This one seems indirect at first but is very short.

Page 20: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

20

Expand this entry ����

Click this next����

Click [Next >] ����

Page 21: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Make Project &Configure

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

21

Click here ����

Give some name (“test”) ����

Page 22: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Run “Auto Config”

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

22

Page 23: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

“Auto Config” found this …

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

23

Click [OK] on next

screen, also, then

this step takes a

few minutes …

Page 24: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Finish makingthe project

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

24

Make sure the “Grammar

Version” your installed Python

Page 25: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Switch to the “Python perspective”

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

25

The “Python perspective” provides all the PyDev tools for developing Python code.

Page 26: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Make a Package …(be sure to select src first)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

26

Page 27: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Make a Module

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

27

Page 28: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Your module in the PyDev eclipse editor

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

28

Page 29: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Add some test code

'''

Created on Mar 16, 2011

@author: Pete

'''

if __name__ == '__main__':

print [i*i for i in range(5)]

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

29

Page 30: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Select this once for each .py to be run

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

30

Page 31: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Results

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

31

Page 32: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Source Code Debugger

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

32

Note:

Set at least one breakpoint or the

debugger will not stop

Page 33: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Debugging happens in the “Debug perspective”

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

33

Page 34: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Paused at first breakpoint

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

34

Page 35: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Example of debugging another project …

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

35

Page 36: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Systems with more than one Python distribution

� Example Linux system has 3 Pythons to choose:

� RedHat Enterprise License v5 server

– Python 2.4 supplied by RedHat

– Found by “Auto Config” in PyDev

� User-installed Enthought Python Distribution in local directory

– Python 2.6

– Manually configured in PyDev

� BCDA Python on /APSshare

– Python 2.5 with CaChannel, CaPython, and ca_utils

– Manually configured in PyDev

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

36

Page 37: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

RHEL5 configuration

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

37

Page 38: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

local EPD Python configuration

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

38

Page 39: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

/APSshare/bin/python configurationexecutable: /APSshare/python25_linux_fc6/bin/python

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

39

Page 40: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Confirm this selection (probably all OK)(note my paths are probably different than yours here, maybe shown like yours on next slide)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

40

Page 41: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Still more work to do … (see next slide)

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

41

Page 42: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Add to the APSshare Python

� Add these folders:

– /APSshare/epics/extension_caPython/lang/python

– /APSshare/python25/lib

– /APSshare/epics/extension_caPython/lib/linux-x86-fc 6/2.5

– /APSshare/pythonlib

� Add this environment variable (ENVIRONMENT tab)

– LD_LIBRARY_PATH /APSshare/python25_linux_fc6/lib:/op t/local/lib

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

42

Click through the [Ok] buttons and accept the new configuration …

LD_LIBRARY_PATH

Page 43: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Getting to the Properties …

� Select your project (“topdoc” here)

� Right click on the project name in the Navigator

� Pop-up menu appears

� Select “Properties” item at bottom of list

� On next screen …

� Select “PyDev – Interpreter/Grammar”

in tree pane (on left)

� Select per next slide

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

43

Page 44: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Selection of Python configuration

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

44

Page 45: PyDev: Developing Python code in Eclipse · – Manually configured in PyDev BCDA Python on /APSshare – Python 2.5 with CaChannel, CaPython, and ca_utils – Manually configured

Thank you for your attention

Pete Jemian:2011-03-16 Python Interest Group: PyDev in Eclipse

45