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.
- Open eclipse, and click Help —> Eclipse Marketplace… menu item at top tool bar.
- Input PyDev in the search text box and click Go button to search. Then click Install button to install it.
- 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.
- 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.
- 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.
- Just click the blue link under the Interpreter section in above dialog. A configure interpreter dialog will popup like below.
- 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.
- 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.
2.2 Create Python Package With PyDev.
- Click File —> New —> Other menu item. Input PyDev and select PyDev Package in the window.
- Input package name in the next dialog, click Finish button.
- Now you can see that the package structure files has been created in the left Package Explorer panel. There is a __init__.py file in each package, you can write package initialization code in this file. Below picture also contains a Login.py file, this is not the package default file, it is just a module file i created, i will introduce it later.
2.3 Create Python Module With PyDev.
- Click File —> New —> Other menu item again.
- Select PyDev &Module wizard at this time.
- 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 login.py file in left package explorer file list.
2.4 Open Exist PyDev Project In Eclipse.
- Open eclipse, then click File —> Open Projects from File System.. menu item.
- Click the Directory… button in the popup window, and select the PyDev project exist directory.
- Click Finish button in above window, then you may meet below popup dialog to let you configure python interpreter.
- Click Choose from list button in above dialog. Then select the python version that you want to use and click OK button.
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.
''' Created on Aug 7, 2018 @author: zhaosong ''' def login(* usernamepassword): username = usernamepassword password = usernamepassword if(username=='hello') and (password == 'hello'): print("Login Success!") else: print("Login Failed!") if __name__ == '__main__': login('hello', 'hello')
3.1 Run Python Code In Eclipse.
- 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.
3.2 Debug Python Code In Eclipse.
- Double click the column before the line number in the source code to set break point.
- 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.