diff --git a/pytools/__init__.py b/pytools/__init__.py
index 8be65a62d6a1f72a2630090fff33e88cac6fb392..50b4f7cf036b242f9a035d15117821a0caf83ea2 100644
--- a/pytools/__init__.py
+++ b/pytools/__init__.py
@@ -1288,9 +1288,9 @@ class CPyUserInterface(object):
         import os
         for arg in argv[1:]:
             if os.access(arg, os.F_OK):
-                exec open(arg, "r") in execenv
+                exec(compile(open(arg, "r"), arg, 'exec'), execenv)
             else:
-                exec arg in execenv
+                exec(compile(arg, "<command line>", 'exec'), execenv)
 
         # check if the user set invalid keys
         for added_key in (