Of course! Here’s a comprehensive guide to using IDLE on Ubuntu, covering what it is, how to install it, how to use it, and some common alternatives.

What is IDLE?
IDLE is the Integrated Development and Learning Environment for Python. It's a basic, lightweight IDE that comes bundled with Python itself.
Key Features:
- Interactive Shell: A command-line prompt where you can type Python code and see the results immediately. Great for quick tests and learning.
- Text Editor: A simple editor for writing, saving, and running Python scripts.
- Debugger: A tool to step through your code line-by-line to find and fix bugs.
- Color Syntax Highlighting: Makes your code easier to read by coloring keywords, strings, and comments.
- Cross-Platform: Works on Windows, macOS, and Linux (like Ubuntu).
It's an excellent choice for:
- Beginners learning Python.
- Writing and running small, simple scripts.
- Quick debugging and testing of code snippets.
How to Install IDLE on Ubuntu
IDLE is not always installed by default when you install Python, but it's very easy to get.

Method 1: The Recommended Way (Using apt)
This is the standard method for Ubuntu. It will install the version of IDLE that matches your system's Python 3.
-
Update your package list:
sudo apt update
-
Install the
idle3package:sudo apt install idle3
This command installs the IDLE environment specifically for Python 3, which is the standard on modern Ubuntu systems.
(图片来源网络,侵删)
Method 2: If Python 3 is Installed via pyenv or deadsnakes
If you installed a specific version of Python (e.g., Python 3.10) using a tool like pyenv or the deadsnakes PPA, you might need to install IDLE for that specific version.
For example, to install IDLE for Python 3.10 from the deadsnakes PPA:
# First, ensure you have the deadsnakes PPA added sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update # Then install idle3.10 sudo apt install idle3.10
You would replace 10 with your desired Python version.
How to Launch and Use IDLE
Once installed, you can launch IDLE in a few ways.
Launching IDLE
-
From the Applications Menu:
- Open your "Activities" overview in the top-left corner.
- Type
idleinto the search bar. - Click on the "IDLE" icon (it looks like a snake wrapped around a gear).
-
From the Command Line:
- Open your terminal (
Ctrl+Alt+T). - Type
idle3and press Enter. - If you have multiple versions, you can specify, e.g.,
idle3.10.
- Open your terminal (
The IDLE Windows
When you launch IDLE, you will see two windows:
-
The Shell Window (Python REPL): This is your interactive interpreter. You can type Python commands directly here and press
Enterto execute them.>>> print("Hello, Ubuntu!") Hello, Ubuntu! >>> 2 + 2 4 >>> my_name = "Alice" >>> print(f"Hello, {my_name}!") Hello, Alice! -
The Editor Window: This is where you write and save your Python scripts (
.pyfiles). You can open it from the Shell window by going to File -> New File.
Basic Workflow in the Editor
-
Open a new file:
File -> New File. -
Write your code:
# hello.py print("This is my first script in IDLE on Ubuntu!") name = input("What is your name? ") print(f"Nice to meet you, {name}!") -
Save the file:
File -> Save(orCtrl+S). Give it a name likehello.py. -
Run the script:
- Go to Run -> Run Module (or press
F5). - The output will appear in the Shell window.
This is my first script in IDLE on Ubuntu! What is your name? Bob Nice to meet you, Bob! >>> - Go to Run -> Run Module (or press
IDLE's Key Features Explained
-
Shell Window:
- Use it for quick calculations, testing functions, or exploring Python's features.
- The
>>>is the prompt, waiting for your input.
-
Editor Window:
- Syntax Highlighting: Keywords (
def,for,if), strings, and comments are all colored differently. - Indentation: Python relies on indentation. IDLE helps by automatically indenting the next line when you press
Enterafter a colon . - Code Completion: You can type part of a function or variable name and press
Alt+/Ctrl+Spaceto see suggestions.
- Syntax Highlighting: Keywords (
-
Debugger:
- This is a powerful tool for finding bugs.
- To use it, open a script in the Editor.
- Set a breakpoint by right-clicking on a line and selecting Set Breakpoint. A red dot will appear.
- Go to Debug -> Debugger to open the debugger control window.
- Go to Debug -> Go (or
F5) to start running. The execution will pause at your breakpoint. - You can step through the code line-by-line using:
- Step: Executes the current line and moves to the next one.
- Over: Executes the current line (but if it's a function call, it runs the whole function at once).
- Out: Finishes executing the current function and returns to where it was called.
Common Alternatives to IDLE on Ubuntu
While IDLE is great for learning, you might want something more powerful as you advance.
| Tool | Best For | Type | Installation |
|---|---|---|---|
| IDLE | Beginners, learning, quick scripts, simple debugging | IDE | sudo apt install idle3 |
| Thonny | Absolute beginners, very simple and clean interface | IDE | sudo apt install thonny |
| Geany | Lightweight programming for multiple languages (Python, C, etc.) | Lightweight IDE | sudo apt install geany |
| VS Code | Professional development, huge extension ecosystem, powerful debugging | Full-Featured IDE | Download from website or sudo apt install code |
| PyCharm | Professional, large-scale Python projects | Professional IDE | Download from website (Community Edition is free) |
| Spyder | Scientific and numerical computing (similar to MATLAB) | IDE | Often comes with Anaconda (conda install spyder) |
For most new users on Ubuntu, IDLE is the perfect starting point. It's simple, always available, and teaches you the fundamentals of how Python code is written and executed.
