在nvidia-docker容器中执行pip3 install kerosene时遇UnicodeDecodeError
Hey there, let's work through this UnicodeDecodeError you're running into when trying to pip3 install kerosene in your nvidia-docker container. The error stems from the fuel dependency (required by kerosene) attempting to read its long description file using ASCII encoding, but the file contains non-ASCII characters—something Python 3.5's default file handling doesn't handle gracefully.
Here are a few straightforward fixes to resolve this:
1. Set UTF-8 Environment Variables Before Installing
The quickest fix is to force Python to use UTF-8 encoding by setting environment variables right before your pip command. Run this in your container:
LC_ALL=C.UTF-8 pip3 install kerosene
Or if you prefer to set the variables first (useful if you're running multiple commands):
export LC_ALL=C.UTF-8 export LANG=C.UTF-8 pip3 install kerosene
This tells Python to use UTF-8 instead of ASCII when reading text files, which should bypass the decoding error entirely.
2. Manually Fix the Fuel Setup.py (If Environment Variables Don't Work)
If the first method fails, you can directly modify the fuel package's setup script to specify the correct encoding:
- Clone the fuel repository:
git clone https://github.com/mila-udem/fuel.git cd fuel - Update the setup.py file to explicitly use UTF-8 when reading the description:
sed -i 's/f.read().strip()/f.read(encoding="utf-8").strip()/' setup.py - Install the modified fuel package:
pip3 install . - Now install kerosene:
pip3 install kerosene
3. Upgrade Python (If Possible)
Python 3.5 is pretty old, and newer Python versions (3.6+) handle file encoding more intelligently (defaulting to UTF-8 in most cases). If your container setup allows it, upgrading to a newer Python base image might prevent this and other similar issues down the line.
Give these steps a shot—option 1 is almost guaranteed to work since encoding mismatches like this are super common in older container environments.
内容的提问来源于stack exchange,提问作者Austin

