How To Run Python In Eclipse With PyDev

Eclipse is the most popular IDE for java development. A lot of user are familiar with it. Besides java project, it can also be used to develop Python application. This article just want to tell you how to use it to develop Python application.

1. Install PyDev Eclipse Plugin.

Before you can develop python app, you should install PyDev ( an eclipse plugin ) in the eclipse. Below is the installation steps.

  1. Open eclipse, and click Help —> Eclipse Marketplace… menu item at top tool bar.
    help eclipse marketplace menu item
  2. Input PyDev in the search text box and click Go button to search. Then click Install button to install it.
    search pydev eclipse plugin
  3. The installation process may take several minutes, and during the process you just need to click Confirm, Next or Finish button. You should restart eclipse when installation complete.

2. Create Eclipse Python Project, Package And Module In PyDev.

After successfully install eclipse PyDev plugin, you can now use it to create python project.

2.1 Create PyDev Python Project In Eclipse.

  1. Open eclipse, and click File —> New —> Other menu item in the top tool bar. And input PyDev in the popup dialog input text box. Then select PyDev Project. Click Next button.
    eclipse create python project with pydev
  2. Then the PyDev Project settings dialog popup. In this dialog, you should select the project directory, input project name, and most importantly you need to configure an interpreter for the PyDev project.
    pydev project settings dialog popup
  3. Just click the blue link under the Interpreter section in above dialog. A configure interpreter dialog will popup like below.
    configure pydev project interpreter popup dialog
  4. Click the Advanced Auto-Config button, it will popup all the installed python interpreter executable file path for you to select, just select the one you need then click OK button.
    select python interpreter installation path
  5. In the next popup dialog, select all the libraries that you want to add to the system python path. Click OK button to complete the PyDev project creation.
    select the python libraries to add to python path

2.2 Create Python Package With PyDev.

  1. Click File —> New —> Other menu item. Input PyDev and select PyDev Package in the window.
    create pydev python package
  2. Input package name in the next dialog, click Finish button.
    input pydev python package name
  3. Now you can see that the package structure files has been created in the left Package Explorer panel. There is a file in each package, you can write package initialization code in this file. Below picture also contains a file, this is not the package default file, it is just a module file i created, i will introduce it later.
    pydev project package and module files list panle

2.3 Create Python Module With PyDev.

  1. Click File —> New —> Other menu item again.
  2. Select PyDev &Module wizard at this time.
    create pydev python package
  3. Select the module package folder, and input the module name, please note the module name is case sensitive. Click Finish button, then you can see the file in left package explorer file list.
    select python module package and input module name

2.4 Open Exist PyDev Project In Eclipse.

  1. Open eclipse, then click File —> Open Projects from File System.. menu item.
    eclipse file - open projects from file system
  2. Click the Directory… button in the popup window, and select the PyDev project exist directory.
    select exist pydev project directory in the eclipse popup dialog window
  3. Click Finish button in above window, then you may meet below popup dialog to let you configure python interpreter.
    python not configured dialog window
  4. Click Choose from list button in above dialog. Then select the python version that you want to use and click OK button.
    select python interpreter installation path

3. Run And Debug Python Code In Eclipse Use PyDev.

Now the login python module has been created, you can copy below python code in it.

def login(* usernamepassword):
    username = usernamepassword[0]
    password = usernamepassword[1]

    if(username=='hello') and (password == 'hello'):
        print("Login Success!")
        print("Login Failed!")

if __name__ == '__main__':
    login('hello', 'hello')

3.1 Run Python Code In Eclipse.

  1. Right click the python file source code, click Run As —> Python Run menu item, then the python file will be executed. You can see output in the bottom console window.
    run as python run

3.2 Debug Python Code In Eclipse.

  1. Double click the column before the line number in the source code to set break point.
  2. Then right click python file source code, click Debug As —> Python Run menu item to run the python code. When it run to the break point, the execution will be paused, you can then watch variable values and debug the code.
    debug as python run
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments

ExampleProject\retryeample\”, line 7
username = usernamepassword[]
SyntaxError: invalid syntax

Jimmy Lee
Jimmy Lee
Reply to  DG

username = usernamepassword[0]

This worked for me.

Would love your thoughts, please comment.x