Có 3 cách chính để khởi động Python:
1. Trình thông dịch tương tác (Interactive Interpreter)
Gõ python tại dòng lệnh Unix/DOS/Windows:
$ python # Unix/Linux python% # Unix/Linux (csh) C:> python # Windows/DOS
Các tùy chọn dòng lệnh phổ biến:
| Tùy chọn | Mô tả |
|---|---|
-d | Debug output |
-O | Tối ưu bytecode (.pyo) |
-S | Không import site ở khởi động |
-v | Verbose (trace import) |
-c cmd | Chạy code từ chuỗi |
file | Chạy script từ file |
2. Script từ dòng lệnh
$ python script.py # Unix/Linux python% script.py # Unix/Linux C:> python script.py # Windows
Lưu ý: Đảm bảo file có quyền thực thi.
3. Môi trường phát triển tích hợp (IDE)
- Unix/Linux: IDLE (cài sẵn), VS Code, PyCharm, Vim/Neovim
- Windows: IDLE, PythonWin, VS Code, PyCharm, Thonny
- macOS: IDLE, VS Code, PyCharm, Xcode
Khắc phục sự cố
- Kiểm tra
python --versionvàpython3 --version - Đảm bảo Python trong PATH
- Linux:
sudo apt install python3/dnf install python3 - Windows: Tải từ python.org/downloads