From 46975aa9c362ff7eaa8fcc667c618cfbaa81af6c Mon Sep 17 00:00:00 2001 From: Erik Selin Date: Thu, 10 Dec 2015 11:18:23 -0500 Subject: [PATCH] Make pyspark shell pythonstartup work under python3 This replaces the execfile used for running custom python shell scripts with explicit open, compile and exec. The reason is to make the pythonstartup option compatible with python3. --- python/pyspark/shell.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/pyspark/shell.py b/python/pyspark/shell.py index 99331297c19f..26cafca8b838 100644 --- a/python/pyspark/shell.py +++ b/python/pyspark/shell.py @@ -76,4 +76,6 @@ # which allows us to execute the user's PYTHONSTARTUP file: _pythonstartup = os.environ.get('OLD_PYTHONSTARTUP') if _pythonstartup and os.path.isfile(_pythonstartup): - execfile(_pythonstartup) + with open(_pythonstartup) as f: + code = compile(f.read(), _pythonstartup, 'exec') + exec(code)