树莓派3B使用Python+pygogo日志报错:No module named builtins
Hey Vikram, let's get this pygogo error sorted out for you. That No module named builtins message is almost always tied to a Python version mismatch—here's why and how to fix it:
Why This Happens
Raspberry Pi 3B typically comes with both Python 2 and Python 3 pre-installed. The builtins module is a Python 3-only built-in module—Python 2 uses __builtin__ (with double underscores) instead. Since pygogo is designed for Python 3+, if you're running your script with Python 2, it'll throw this exact error.
Step-by-Step Fixes
Check your default Python version
Run these commands in your terminal to confirm which versions you're working with:python --version python3 --versionIf
python --versionshows Python 2.x, that's the root cause.Run your script with Python 3
Instead of usingpython your_log_script.py, use the Python 3 interpreter explicitly:python3 your_log_script.pyEnsure pygogo is installed for Python 3
If you originally installed pygogo withpip install pygogo, it probably got installed to your Python 2 environment. Install it for Python 3 instead:# First install pip3 if you don't have it sudo apt-get update && sudo apt-get install python3-pip -y # Then install pygogo for Python 3 pip3 install pygogo
Bonus: Set Python 3 as your default (optional)
If you want to avoid this confusion in the future, you can set Python 3 as your default python command:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
That should resolve the builtins module error and get your pygogo logging up and running on the Pi 3B.
内容的提问来源于stack exchange,提问作者vikram eklare

