python: Insert gem5's m5 importer at the front of sys.meta_path.

This is equivalent to putting a path first in $PATH, ie it will make
sure that resolves to gem5's internal m5 package, and not
whatever directory named m5 happens to be nearby.

Change-Id: I762d47da8ed8e4cfdf03e412d7dd7cc91a691b58
Reviewed-by: Gabe Black <>
Maintainer: Gabe Black <>
Tested-by: kokoro <>
diff --git a/src/python/ b/src/python/
index baeae21..94edb91 100644
--- a/src/python/
+++ b/src/python/
@@ -77,4 +77,4 @@
 import sys
 importer = CodeImporter()
 add_module = importer.add_module
+sys.meta_path.insert(0, importer)