diff --git a/bin/compile b/bin/compile
index adf3fdd6cacecd9f1eba29fdfe0f90735f32209a..3d3d3b2fe95c886b92cf71deb49d1584eaee2a04 100755
--- a/bin/compile
+++ b/bin/compile
@@ -27,8 +27,9 @@ BUILD_DIR=$1
 CACHE_DIR=$2
 ENV_DIR=$3
 
-# Export path environment variables for sub-scripts.
-export BIN_DIR ROOT_DIR BUILD_DIR CACHE_DIR ENV_DIR
+# Static configurations for virtualenv caches.
+VIRTUALENV_LOC=".heroku/venv"
+LEGACY_TRIGGER="lib/python2.7"
 
 DEFAULT_PYTHON_VERSION="python-2.7.13"
 DEFAULT_PYTHON_STACK="cedar-14"
@@ -132,35 +133,33 @@ fi
 # Prepare the cache.
 mkdir -p $CACHE_DIR
 
+# Purge "old-style" virtualenvs.
+bpwatch start clear_old_venvs
+  [ -d $CACHE_DIR/$LEGACY_TRIGGER ] && rm -fr $CACHE_DIR/.heroku/bin $CACHE_DIR/.heroku/lib $CACHE_DIR/.heroku/include
+  [ -d $CACHE_DIR/$VIRTUALENV_LOC ] && rm -fr $CACHE_DIR/.heroku/venv $CACHE_DIR/.heroku/src
+bpwatch stop clear_old_venvs
+
 # Restore old artifacts from the cache.
 bpwatch start restore_cache
-  mkdir -p .heroku
-
-  cp -R $CACHE_DIR/.heroku/python .heroku/ &> /dev/null || true
-  cp -R $CACHE_DIR/.heroku/python-stack .heroku/ &> /dev/null || true
-  cp -R $CACHE_DIR/.heroku/python-version .heroku/ &> /dev/null || true
-  cp -R $CACHE_DIR/.heroku/vendor .heroku/ &> /dev/null || true
-  cp -R $CACHE_DIR/.heroku/venv .heroku/ &> /dev/null || true
-
-  if [[ -d $CACHE_DIR/.heroku/src ]]; then
-    cp -R $CACHE_DIR/.heroku/src .heroku/ &> /dev/null || true
-  fi
+    mkdir -p .heroku
 
+    cp -R $CACHE_DIR/.heroku/python .heroku/ &> /dev/null || true
+    cp -R $CACHE_DIR/.heroku/python-stack .heroku/ &> /dev/null || true
+    cp -R $CACHE_DIR/.heroku/python-version .heroku/ &> /dev/null || true
+    cp -R $CACHE_DIR/.heroku/vendor .heroku/ &> /dev/null || true
+    cp -R $CACHE_DIR/.heroku/venv .heroku/ &> /dev/null || true
 
 bpwatch stop restore_cache
 
 mkdir -p $(dirname $PROFILE_PATH)
 
-# Make the directory for -e pip installations.
-mkdir -p /app/.heroku/src
-
 if [[ $BUILD_DIR != '/app' ]]; then
-  # python expects to reside in /app, so set up symlinks
-  # we will not remove these later so subsequent buildpacks can still invoke it
-  ln -s $BUILD_DIR/.heroku/python /app/.heroku/python
-  ln -s $BUILD_DIR/.heroku/vendor /app/.heroku/vendor
-  ln -s $BUILD_DIR/.heroku/venv /app/.heroku/venv
-  # NOTE: /app/.heroku/src also exists, but is copied manually later.
+    # python expects to reside in /app, so set up symlinks
+    # we will not remove these later so subsequent buildpacks can still invoke it
+    ln -s $BUILD_DIR/.heroku/python /app/.heroku/python
+    ln -s $BUILD_DIR/.heroku/src /app/.heroku/src
+    ln -s $BUILD_DIR/.heroku/vendor /app/.heroku/vendor
+    ln -s $BUILD_DIR/.heroku/venv /app/.heroku/venv
 fi
 
 # Install Python.
@@ -187,13 +186,20 @@ sub-env $BIN_DIR/steps/geo-libs
 # GDAL support.
 source $BIN_DIR/steps/gdal
 
+# rewrite any existing egg links to point to the build dir so pip does not fail with a mismatch error
+find .heroku/python/lib/python*/site-packages/ -name "*.egg-link" -print0 | xargs -r -0 -n 1 sed -i -e "s#/app/#$(pwd)/#"
+find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 | xargs -r -0 -n 1 sed -i -e "s#/app/#/$(pwd)/#"
+
 # Install dependencies with Pip.
 source $BIN_DIR/steps/pip-install
 
+# rewrite build dir in egg links to /app so things are found at runtime
+find .heroku/python/lib/python*/site-packages/ -name "*.egg-link" -print0 | xargs -r -0 -n 1 sed -i -e "s#$(pwd)/#/app/#"
+find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 | xargs -r -0 -n 1 sed -i -e "s#$(pwd)/#/app/#"
+
 # Django collectstatic support.
 sub-env $BIN_DIR/steps/collectstatic
 
-
 # Create .profile script for application runtime environment variables.
 set-env PATH '$HOME/.heroku/python/bin:$PATH'
 set-env PYTHONUNBUFFERED true
@@ -207,11 +213,6 @@ set-default-env PYTHONPATH /app/
 # Install sane-default script for $WEB_CONCURRENCY and $FORWARDED_ALLOW_IPS.
 cp $ROOT_DIR/vendor/python.gunicorn.sh $GUNICORN_PROFILE_PATH
 
-# Symlink the directory for -e pip installations
-if [[ $BUILD_DIR != '/app' ]]; then
-  deep-cp /app/.heroku/src $BUILD_DIR/.heroku/src
-  ln -s /app/.heroku/src $BUILD_DIR/.heroku/src
-fi
 
 # Experimental post_compile hook.
 bpwatch start post_compile
@@ -226,7 +227,6 @@ bpwatch start dump_cache
   rm -rf $CACHE_DIR/.heroku/python-stack
   rm -rf $CACHE_DIR/.heroku/vendor
   rm -rf $CACHE_DIR/.heroku/venv
-  rm -rf $CACHE_DIR/.heroku/src
 
   mkdir -p $CACHE_DIR/.heroku
   cp -R .heroku/python $CACHE_DIR/.heroku/
@@ -234,7 +234,6 @@ bpwatch start dump_cache
   cp -R .heroku/python-stack $CACHE_DIR/.heroku/ &> /dev/null || true
   cp -R .heroku/vendor $CACHE_DIR/.heroku/ &> /dev/null || true
   cp -R .heroku/venv $CACHE_DIR/.heroku/ &> /dev/null || true
-  cp -R .heroku/src $CACHE_DIR/.heroku/ &> /dev/null || true
 
 bpwatch stop dump_cache