Saturday, March 28, 2015

Python in Eclipse ( PyDev )

Eclipse is an excellent choice for beginning programmers not just because of its feature rich interface, but also for its support for many programming languages.  These days, I would suggest starting with C/C++ then move to Java and last try to also learn Python for a "well rounded" computer science skill arsenal.  
Installation steps
1. Download the latest Java JDK
2. Download Eclipse IDE
3. Download Python
4. When Eclipse is running and the workspace is configured, you can just drag and drop the PyDev icon directly from the browser to the Eclipse workspace or install it manually. 

Browser drop: http://marketplace.eclipse.org/content/pydev-python-ide-eclipse 

 
PyDEv requirements, at least one of:



Click on Help and then Install New Software ....  Add the source to PyDev ( http://pydev.org/updates  ) and select the PyDev software installation.  It will take a few minutes to install and you will need to restart Eclipse for the installation to finish. 



Your First Project

That is all that you will need to install Python in your Eclipse IDE and start developing software in this new language. 

You can create a new Python PyDev module and quickly learn the basics.

File->New -> PyDev Module
Give it a name like “testProject” and leave everything else default.  If you receive a message when you create the PyDev module about the interpreter not being configured, just select the auto configuration option or manually point your IDE to the python.exe file from the path you chose to install Python into.


Example Code and Output


import sys
'Examples from: https://wiki.python.org/moin/SimplePrograms'

parents, babies = (1, 1)
while babies < 100:
print 'This generation has {0} babies'.format(babies)
parents, babies = (babies, parents + babies)
# This program adds up integers in the command line
try:
total = sum(int(arg) for arg in sys.argv[1:])
print 'sum =', total
except ValueError:
print 'Please supply integer arguments'


Output:

This generation has 1 babies
This generation has 2 babies
This generation has 3 babies
This generation has 5 babies
This generation has 8 babies
This generation has 13 babies
This generation has 21 babies
This generation has 34 babies
This generation has 55 babies
This generation has 89 babies
sum = 1500

No comments:

Post a Comment