# Buggy code
def list_packages(
    prefix,
    installed,
    regex=None,
    format="human",
    show_channel_urls=context.show_channel_urls,
):
    res = 0
    result = []
    for dist in get_packages(installed, regex):
        if format == "canonical":
            result.append(dist)
            continue
        if format == "export":
            result.append("=".join(dist.quad[:3]))
            continue

        try:
            # Returns None if no meta-file found (e.g. pip install)
            info = is_linked(prefix, dist)
            features = set(info.get("features", "").split())
            disp = "%(name)-25s %(version)-15s %(build)15s" % info
            disp += "  %s" % disp_features(features)
            schannel = info.get("schannel")
            if (
                show_channel_urls
                or show_channel_urls is None
                and schannel != DEFAULTS_CHANNEL_NAME
            ):
                disp += "  %s" % schannel
            result.append(disp)
        except (AttributeError, IOError, KeyError, ValueError) as e:
            log.debug("exception for dist %s:\n%r", dist, e)
            result.append("%-25s %-15s %15s" % tuple(dist.quad[:3]))

    return res, result


# Traceback (ImportError)
Traceback (most recent call last):
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/exceptions.py", line 573, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 98, in _main
imported = importlib.import_module(module)
File "/Users/tasalta/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/cli/main_list.py", line 20, in <module>
from ..egg_info import get_egg_info
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/egg_info.py", line 15, in <module>
from .misc import rel_path
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/misc.py", line 19, in <module>
from .core.index import get_index, _supplement_index_with_cache
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/Users/tasalta/anaconda/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: cannot import name InsecureRequestWarning


at throwCondaError (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:117:9)
at runConda (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:146:5)
at Object.info (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/conda.js:395:10)
at Object.isGLCLauncherReady (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/utils/systemState.js:207:27)
at [object Object].onWindowOpen [as _onTimeout] (/Applications/GraphLab Create Launcher.app/Contents/Resources/app.asar/main.js:144:57)
at Timer.listOnTimeout (timers.js:89:15)

# Fixed code
def list_packages(
    prefix, installed, regex=None, format="human", show_channel_urls=None
):
    from .common import disp_features
    from ..base.constants import DEFAULTS_CHANNEL_NAME
    from ..base.context import context
    from ..core.linked_data import is_linked

    res = 0
    result = []
    for dist in get_packages(installed, regex):
        if format == "canonical":
            result.append(dist)
            continue
        if format == "export":
            result.append("=".join(dist.quad[:3]))
            continue

        try:
            # Returns None if no meta-file found (e.g. pip install)
            info = is_linked(prefix, dist)
            features = set(info.get("features", "").split())
            disp = "%(name)-25s %(version)-15s %(build)15s" % info
            disp += "  %s" % disp_features(features)
            schannel = info.get("schannel")
            show_channel_urls = show_channel_urls or context.show_channel_urls
            if (
                show_channel_urls
                or show_channel_urls is None
                and schannel != DEFAULTS_CHANNEL_NAME
            ):
                disp += "  %s" % schannel
            result.append(disp)
        except (AttributeError, IOError, KeyError, ValueError) as e:
            log.debug("exception for dist %s:\n%r", dist, e)
            result.append("%-25s %-15s %15s" % tuple(dist.quad[:3]))

    return res, result