diff --git a/news/5021.bugfix b/news/5021.bugfix new file mode 100644 index 00000000000..4de60b18e76 --- /dev/null +++ b/news/5021.bugfix @@ -0,0 +1 @@ +Package name should be normalized before we use it to search if it's already installed or not diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 3b28209b1bd..d1a7b9c3de8 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -420,12 +420,16 @@ def check_if_exists(self, use_user_site): """ if self.req is None: return + + # Canonicalize requirement name to use normalized + # names while searching for already installed packages + no_marker = Requirement(str(self.req)) + no_marker.marker = None + no_marker.name = canonicalize_name(no_marker.name) # get_distribution() will resolve the entire list of requirements # anyway, and we've already determined that we need the requirement # in question, so strip the marker so that we don't try to # evaluate it. - no_marker = Requirement(str(self.req)) - no_marker.marker = None try: self.satisfied_by = pkg_resources.get_distribution(str(no_marker)) except pkg_resources.DistributionNotFound: