Monday, December 28, 2009

Integrate Pydev in Eclipse for Ubuntu

1) find and download Pydev (.tar) file


2) unpack it


3)Setting up a python interpreter

    i) Windows > Preferences:



   ii)Find Pydev on the left hand side and select Interpreter - Python.
 
   iii)Click the New button on the right hand side and pick your python version, usually installed to /usr/bin/python<version #>:



iv)It should load several python libraries and populate the PYTHONPATH. Click OK to save this as your interpreter.

4) Setting up a python project

  i) Run -> run configurations


              
 ii)Click on the ‘new’ icon above “type filter text” and select the interpreted we just added in preferences.



                    
 iii)Add the project to this configuration and give it a name:



 iv)Click Run


Pydev works well for mid size projects or bigger.  I usually use Idle for smaller programs or ones that I will use only once and switch to eclipse when the project is bigger than Idle’s window.

Installing python on Linux

If you are lucky enough to be running Linux, you install Python through the apt command.

localhost:~$ sudo -
 
Password: [enter your root password]
 
localhost:~# apt-get install python
 
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  python2.3
Suggested packages:
  python-tk python2.3-doc
The following NEW packages will be installed:
  python python2.3
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 0B/2880kB of archives.
After unpacking 9351kB of additional disk space will be used.
 
Do you want to continue? [Y/n] Y
 
Selecting previously deselected package python2.3.
(Reading database ... 22848 files and directories currently installed.)
Unpacking python2.3 (from .../python2.3_2.3.1-1_i386.deb) ...
Selecting previously deselected package python.
Unpacking python (from .../python_2.3.1-1_all.deb) ...
Setting up python (2.3.1-1) ...
Setting up python2.3 (2.3.1-1) ...
Compiling python modules in /usr/lib/python2.3 ...
Compiling optimized python modules in /usr/lib/python2.3 ...
localhost:~# exit
logout
 
localhost:~$ python
 
Python 2.3.1 (#2, Sep 24 2003, 11:39:14)
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 
>>> [press Ctrl+D to exit]

Ubuntu Linux: Install Eclipse Java Integrated Development Environment

 

Install Sun JDK and JRE

Open terminal and type the following commands to install Sun Java JDK and JRE:
 
$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
$ sudo vi /etc/jvm


Add following line at the top:
 
/usr/lib/jvm/java-6-sun

Set up environment:
 
$ echo 'export JAVA_HOME=/usr/lib/jvm/java-6-sun' >> ~/.bash_profile
$ echo 'export PATH=$PATH:$JAVA_HOME/bin' >> ~/.bash_profile
$ . ~/.bash_profile


Make sure you see correct JAVA version:
 
$ java -version

Sample output:
 
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

Install Eclipse

Type the following command to install extensible Tool Platform, Java IDE, Java Development Tools plug-ins for Eclipse:
 
$ sudo apt-get install eclipse eclipse-jdt

How do I start eclipse?

Click on Applications > Programming > Eclipse

OR type the following command at shell prompt:
 
$ eclipse &

You should see an eclipse splash screen followed by workspace launcher:



 Fig.01: Eclipse IDE workspace Launcher

Your first java program using Eclipse

Click Ok to load IDE. Close welcome screen. Click on Windows > Open perspective > Select Java .

Step # 1: Create a project

You need to create a project to put all .java and related project files. Click on File > New > Project > Select Java Project


Fig.01: Creating first java project

Click Next > Type Project name "HelloWorld" > Click on Finish:


Fig.02: HelloWorld Project

Step # 3: Create a new class

Now you need add a new class called HelloWorld. Click on File > New > Class > Set class name to "HelloWorld" > Select the checkbox to create the main() method > click Finish button:





Fig.03: Adding your first class called HelloWorld

Step # 3: Type the code

Type the following code inside main() method:
 
System.out.println("Hello world!\n");
 


Fig.04: Your first java program using Eclipse Java IDE

Press CTRL + S to save program (or visit File > Save option).