From a45367d9b728b56d4d64a7f6ad8be07c2e871d59 2018-06-13 09:19:50
From: Min RK <benjaminrk@gmail.com>
Date: 2018-06-13 09:19:50
Subject: [PATCH] Merge pull request #11172 from cedric05/master

check that virtualenv dir exists before using it
---

diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
index 69bf523..9d17bdf 100644
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -737,7 +737,7 @@ class InteractiveShell(SingletonConfigurable):
 
         # executable path should end like /bin/python or \\scripts\\python.exe
         p_exe_up2 = os.path.dirname(os.path.dirname(p))
-        if p_exe_up2 and os.path.samefile(p_exe_up2, p_venv):
+        if p_exe_up2 and os.path.exists(p_venv) and os.path.samefile(p_exe_up2, p_venv):
             # Our exe is inside the virtualenv, don't need to do anything.
             return