Ubuntu 20.04环境下如何修复.repo/repo/main.py语法错误问题?
repo init for Pelux Hey there, let's work through that Python syntax error you're hitting with the repo command. This issue almost always traces back to a Python version mismatch—modern repo tools (and the Pelux manifests) require Python 3.x, but your system is probably trying to run it with Python 2.x. Here's how to fix it step by step:
1. Verify Your Default Python Version
First, check which Python version your system uses by default:
python --version python3 --version
If python --version shows a 2.x release (like Python 2.7), that's the root problem. The line print(..., file=sys.stderr) in main.py uses Python 3 syntax that's invalid in Python 2, since Python 2 treats print as a statement instead of a function.
2. Force repo to Use Python 3
You have a couple straightforward ways to do this:
Option A: Update the repo Script's Shebang Line
Find the path to your repo script (run which repo to locate it, or check your .repo/repo/ directory). Open it in a text editor and change the first line from:
#!/usr/bin/env python
to:
#!/usr/bin/env python3
Option B: Call repo Directly with Python 3
Instead of running repo init, execute the command using Python 3 explicitly:
python3 $(which repo) init -u https://github.com/Pelagicore/pelux-manifests.git -b master
3. Set Python 3 as Your System Default (Optional but Recommended)
To avoid this issue for future commands, set Python 3 as your system's default Python:
For Debian/Ubuntu-based systems:
sudo apt update && sudo apt install python3 python3-pip sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 sudo update-alternatives --config python # Select Python 3 from the menu that appears
For RHEL/CentOS-based systems:
sudo yum install python3 sudo alternatives --set python /usr/bin/python3
4. Clean Up and Reinitialize
Sometimes leftover cache files can cause unexpected issues. Delete the existing .repo directory and start fresh with Python 3:
rm -rf .repo python3 repo init -u https://github.com/Pelagicore/pelux-manifests.git -b master
Quick Breakdown of the Error
The line throwing the error uses Python 3-specific syntax: passing file= as a keyword argument to print(). Python 2 doesn't support this because print is a statement, not a function there. Since modern repo versions are built for Python 3, ensuring it runs with the correct version resolves the syntax conflict.
内容的提问来源于stack exchange,提问作者artur_roomman




