TensorFlow 1.4.0中saved_model_utils.py导入reader.py失败求助
Hey, let's work through this import problem you're hitting with saved_model_utils.py trying to load reader.py in TensorFlow 1.4.0 while using Unity ML-Agents v0.3. Here are some practical fixes to try:
1. Verify Python Path & Package Structure
First, double-check that Python can properly locate TensorFlow's internal modules. In TensorFlow 1.4.0, both saved_model_utils.py and reader.py should live in the tensorflow/python/saved_model directory.
If your training script is running from the Unity ML-Agents folder, it might be messing with your sys.path and preventing Python from finding the right TensorFlow files. Add this code at the very top of your training script to debug and fix the path:
import sys # Print current paths to check if TensorFlow's directory is included print("Current Python Paths:", sys.path) # If TensorFlow's site-packages path is missing, add it manually (update the path below) sys.path.append("/your/python/site-packages/tensorflow") # Try importing directly to test from tensorflow.python.saved_model import reader
2. Fix the Import Statement (Quick Workaround)
Since the official TensorFlow package shouldn't have broken imports, this is likely a path quirk in your environment. You can manually adjust the import in saved_model_utils.py:
- Find the original relative import (looks like
from . import reader) - Replace it with an absolute import:
from tensorflow.python.saved_model import reader
This bypasses relative import issues by pointing directly to the module's full path.
3. Reinstall TensorFlow 1.4.0
Corrupted or misinstalled packages can cause weird path issues. Completely remove your current TensorFlow installation and reinstall the exact version:
pip uninstall tensorflow -y pip install tensorflow==1.4.0
After reinstalling, confirm both saved_model_utils.py and reader.py exist in tensorflow/python/saved_model—missing files are a common culprit here.
4. Ensure Unity ML-Agents is Run Correctly
Unity ML-Agents v0.3 is compatible with TF 1.4.0, but make sure you're running the training script from the right directory. Follow the official steps:
cd /path/to/your/ml-agents/python python train.py --run-id=your_run_name --env=../environments/your_unity_env.exe
This ensures the script uses the correct environment variables and paths set up by ML-Agents.
From your screenshots, it's clear reader.py exists in your project, but Python's runtime path doesn't match what your project window shows—focus on debugging sys.path to align the two.
内容的提问来源于stack exchange,提问作者sam ulrich

