docker-compose执行报错:ValueError: bad marshal data (unknown type code)
docker-compose --help Oh, I’ve run into this exact error before—it’s caused by corrupted Python bytecode files (.pyc) for the docker-compose package, specifically in your Python 2.7 setup. Here’s how to fix it step by step:
Uninstall the broken docker-compose installation
First, remove the current corrupted package using pip (usepip2if your default pip points to Python 3):pip uninstall -y docker-composeClean up leftover corrupted files
Sometimes the uninstall process leaves behind broken bytecode or residual directories. Delete the compose folder from your Python 2.7 dist-packages:rm -rf /usr/local/lib/python2.7/dist-packages/compose/Reinstall docker-compose (prefer the standalone binary for stability)
To avoid future Python dependency headaches, skip the pip install and use the official standalone binary:- Download the appropriate stable version for your operating system and architecture from the Docker Compose releases.
- Save the file to
/usr/local/bin/docker-compose. - Make it executable with this command:
chmod +x /usr/local/bin/docker-compose
Once you’ve completed these steps, run docker-compose --help again—it should work without that marshal data error. The root cause was that a compiled Python file for the compose CLI got corrupted (this can happen from sudden power loss, disk glitches, or Python version mismatches), so Python couldn’t parse it when trying to load the module.
内容的提问来源于stack exchange,提问作者GitProphet

