Blame SOURCES/remove-existing-dist-only-if-path-conflicts.patch

7e1da2
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
7e1da2
index 6911fba..8524932 100644
7e1da2
--- a/pip/req/req_install.py
7e1da2
+++ b/pip/req/req_install.py
7e1da2
@@ -34,7 +34,7 @@ from pip.locations import (
7e1da2
 )
7e1da2
 from pip.utils import (
7e1da2
     display_path, rmtree, ask_path_exists, backup_dir, is_installable_dir,
7e1da2
-    dist_in_usersite, dist_in_site_packages, egg_link_path,
7e1da2
+    dist_in_usersite, dist_in_site_packages, dist_in_install_path, egg_link_path,
7e1da2
     call_subprocess, read_text_file, FakeFile, _make_build_dir, ensure_dir,
7e1da2
     get_installed_version, normalize_path, dist_is_local,
7e1da2
 )
7e1da2
@@ -1049,7 +1049,7 @@ class InstallRequirement(object):
7e1da2
                         "lack sys.path precedence to %s in %s" %
7e1da2
                         (existing_dist.project_name, existing_dist.location)
7e1da2
                     )
7e1da2
-            else:
7e1da2
+            elif dist_in_install_path(existing_dist):
7e1da2
                 self.conflicts_with = existing_dist
7e1da2
         return True
7e1da2
 
7e1da2
diff --git a/pip/req/req_set.py b/pip/req/req_set.py
7e1da2
index 76aec06..b93304a 100644
7e1da2
--- a/pip/req/req_set.py
7e1da2
+++ b/pip/req/req_set.py
7e1da2
@@ -18,7 +18,8 @@ from pip.exceptions import (InstallationError, BestVersionAlreadyInstalled,
7e1da2
                             UnsupportedPythonVersion)
7e1da2
 from pip.req.req_install import InstallRequirement
7e1da2
 from pip.utils import (
7e1da2
-    display_path, dist_in_usersite, ensure_dir, normalize_path)
7e1da2
+    display_path, dist_in_usersite, dist_in_install_path, ensure_dir,
7e1da2
+    normalize_path)
7e1da2
 from pip.utils.hashes import MissingHashes
7e1da2
 from pip.utils.logging import indent_log
7e1da2
 from pip.utils.packaging import check_dist_requires_python
7e1da2
@@ -437,10 +438,12 @@ class RequirementSet(object):
7e1da2
 
7e1da2
                 if not best_installed:
7e1da2
                     # don't uninstall conflict if user install and
7e1da2
-                    # conflict is not user install
7e1da2
+                    # conflict is not user install or conflict lives
7e1da2
+                    # in a different path (/usr/lib vs /usr/local/lib/)
7e1da2
                     if not (self.use_user_site and not
7e1da2
-                            dist_in_usersite(req_to_install.satisfied_by)):
7e1da2
-                        req_to_install.conflicts_with = \
7e1da2
+                            dist_in_usersite(req_to_install.satisfied_by) or not
7e1da2
+                            dist_in_install_path(req_to_install.satisfied_by)):
7e1da2
+                        req_to_install.conflicts_with = \
7e1da2
                             req_to_install.satisfied_by
7e1da2
                     req_to_install.satisfied_by = None
7e1da2
 
7e1da2
@@ -644,10 +647,12 @@ class RequirementSet(object):
7e1da2
                 if req_to_install.satisfied_by:
7e1da2
                     if self.upgrade or self.ignore_installed:
7e1da2
                         # don't uninstall conflict if user install and
7e1da2
-                        # conflict is not user install
7e1da2
+                        # conflict is not user install or conflict lives
7e1da2
+                        # in a different path (/usr/lib vs /usr/local/lib/)
7e1da2
                         if not (self.use_user_site and not
7e1da2
                                 dist_in_usersite(
7e1da2
-                                    req_to_install.satisfied_by)):
7e1da2
+                                    req_to_install.satisfied_by) or not
7e1da2
+                                dist_in_install_path(req_to_install.satisfied_by)):
7e1da2
                             req_to_install.conflicts_with = \
7e1da2
                                 req_to_install.satisfied_by
7e1da2
                         req_to_install.satisfied_by = None
7e1da2
diff --git a/pip/utils/__init__.py b/pip/utils/__init__.py
7e1da2
index 815bd33..0ed59f7 100644
7e1da2
--- a/pip/utils/__init__.py
7e1da2
+++ b/pip/utils/__init__.py
7e1da2
@@ -22,7 +22,7 @@ from pip.exceptions import InstallationError
7e1da2
 from pip.compat import console_to_str, expanduser, stdlib_pkgs
7e1da2
 from pip.locations import (
7e1da2
     site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
7e1da2
-    write_delete_marker_file,
7e1da2
+    write_delete_marker_file, distutils_scheme,
7e1da2
 )
7e1da2
 from pip._vendor import pkg_resources
7e1da2
 from pip._vendor.six.moves import input
7e1da2
@@ -315,6 +315,16 @@ def dist_in_site_packages(dist):
7e1da2
     ).startswith(normalize_path(site_packages))
7e1da2
 
7e1da2
 
7e1da2
+def dist_in_install_path(dist):
7e1da2
+    """
7e1da2
+    Return True if given Distribution is installed in
7e1da2
+    path matching distutils_scheme layout.
7e1da2
+    """
7e1da2
+    norm_path = normalize_path(dist_location(dist))
7e1da2
+    return norm_path.startswith(normalize_path(
7e1da2
+        distutils_scheme("")['purelib'].split('python')[0]))
7e1da2
+
7e1da2
+
7e1da2
 def dist_is_editable(dist):
7e1da2
     """Is distribution an editable install?"""
7e1da2
     for path_item in sys.path: