diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index c12cfa1..6e3b0f1 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -732,6 +732,16 @@ class InteractiveShell(SingletonConfigurable): # Not in a virtualenv return + # Handle no symbolic link case first. + if not os.path.islink(sys.executable): + # Adapted from pip.locations.running_under_virtualenv + if hasattr(sys, 'real_prefix'): + # Running properly in a virtualenv + return + elif sys.prefix != getattr(sys, "base_prefix", sys.prefix): + # Running properly in a venv + return + # venv detection: # stdlib venv may symlink sys.executable, so we can't use realpath. # but others can symlink *to* the venv Python, so we can't just use sys.executable.