diff --git a/IPython/core/application.py b/IPython/core/application.py index 19d0910..b13410d 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -146,6 +146,20 @@ class BaseIPythonApplication(Application): def __init__(self, **kwargs): super(BaseIPythonApplication, self).__init__(**kwargs) + # ensure current working directory exists + level_up = False + while True: + try: + directory = os.getcwdu() + except OSError: + # search level up until directory exists + os.chdir("..") + level_up = True + else: + if level_up: + self.log.warn("Current working directory doesn't exist.\nSetting to: %s"%(directory)) + break + # ensure even default IPYTHONDIR exists if not os.path.exists(self.ipython_dir): self._ipython_dir_changed('ipython_dir', self.ipython_dir, self.ipython_dir)