# Buggy code
def create_package_set_from_installed(**kwargs):
    # type: (**Any) -> Tuple[PackageSet, bool]
    """Converts a list of distributions into a PackageSet."""
    # Default to using all packages installed on the system
    if kwargs == {}:
        kwargs = {"local_only": False, "skip": ()}

    package_set = {}
    problems = False
    for dist in get_installed_distributions(**kwargs):
        name = canonicalize_name(dist.project_name)
        try:
            package_set[name] = PackageDetails(dist.version, dist.requires())
        except RequirementParseError as e:
            # Don't crash on broken metadata
            logger.warning("Error parsing requirements for %s: %s", name, e)
            problems = True
    return package_set, problems


# Traceback (AttributeError)
C:\Users\elcot>pip install scipy
Requirement already satisfied: scipy in c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages (1.4.1)
Requirement already satisfied: numpy>=1.13.3 in c:\users\elcot\appdata\roaming\python\python38\site-packages (from scipy) (1.19.0)
ERROR: Error while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new
Traceback (most recent call last):
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3021, in _dep_map
return self.__dep_map
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2815, in __getattr__
raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3012, in _parsed_pkg_info
return self._pkg_info
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2815, in __getattr__
raise AttributeError(attr)
AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\install.py", line 535, in _determine_conflicts
return check_install_conflicts(to_install)
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\operations\check.py", line 108, in check_install_conflicts
package_set, _ = create_package_set_from_installed()
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\operations\check.py", line 50, in create_package_set_from_installed
package_set[name] = PackageDetails(dist.version, dist.requires())
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2736, in requires
dm = self._dep_map
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3023, in _dep_map
self.__dep_map = self._compute_dependencies()
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3032, in _compute_dependencies
for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3014, in _parsed_pkg_info
metadata = self.get_metadata(self.PKG_INFO)
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1420, in get_metadata
value = self._get(path)
File "c:\users\elcot\appdata\local\programs\python\python38\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1616, in _get
with open(path, 'rb') as stream:
PermissionError: [Errno 13] Permission denied: 'c:\\users\\elcot\\appdata\\roaming\\python\\python38\\site-packages\\astroid-2.4.2.dist-info\\METADATA'

# Fixed code
def create_package_set_from_installed(**kwargs):
    # type: (**Any) -> Tuple[PackageSet, bool]
    """Converts a list of distributions into a PackageSet."""
    # Default to using all packages installed on the system
    if kwargs == {}:
        kwargs = {"local_only": False, "skip": ()}

    package_set = {}
    problems = False
    for dist in get_installed_distributions(**kwargs):
        name = canonicalize_name(dist.project_name)
        try:
            package_set[name] = PackageDetails(dist.version, dist.requires())
        except (OSError, RequirementParseError) as e:
            # Don't crash on unreadable or broken metadata
            logger.warning("Error parsing requirements for %s: %s", name, e)
            problems = True
    return package_set, problems