diff --git a/scripts/ost.in b/scripts/ost.in
index a20bef97b4fea5f3b1d98690aadea2c2d83f5677..6da63bda457579ce183cca42bbac47b84d77a4c5 100755
--- a/scripts/ost.in
+++ b/scripts/ost.in
@@ -47,7 +47,7 @@ if test -e "${OST_SCRIPT}" ; then
       fi
     done
     IFS="#"
-    $pyexec -c "execfile('$DNG_ROOT/@LIBDIR@/python@PYTHON_VERSION@/site-packages/ost/ost_startup.py')" "${OST_SCRIPT}" $opts
+    $pyexec -c "exec(open('$DNG_ROOT/@LIBDIR@/python@PYTHON_VERSION@/site-packages/ost/ost_startup.py').read())" "${OST_SCRIPT}" $opts
     RC=$?
 else
     opts=""
@@ -59,7 +59,7 @@ else
       fi
     done
     IFS="#"
-    $pyexec $interactive -c "execfile('$DNG_ROOT/@LIBDIR@/python@PYTHON_VERSION@/site-packages/ost/ost_startup.py')" $opts
+    $pyexec $interactive -c "exec(open('$DNG_ROOT/@LIBDIR@/python@PYTHON_VERSION@/site-packages/ost/ost_startup.py').read())" $opts
     RC=$?
 fi
 IFS=$OLDIFS
diff --git a/scripts/ost_startup.py.in b/scripts/ost_startup.py.in
index ed156415b61126ee2845b714d2f68c749d8bd0f6..6a5addab27e50c29ebbcb488f956c30c5b0d9127 100644
--- a/scripts/ost_startup.py.in
+++ b/scripts/ost_startup.py.in
@@ -73,7 +73,7 @@ home = os.getenv('HOME') or os.getenv('USERPROFILE')
 _ostrc=os.path.join(home, '.ostrc')
 if os.path.exists(_ostrc):
   try:
-    exec(open(_ostrc))
+    exec(compile(open(_ostrc).read(), _ostrc, 'exec'))
   except Exception as e:
     print(e)
 PushVerbosityLevel(options.vlevel)