# Buggy code
def pip_install_deps(requirements_path):
    """Pip install a requirements.txt file and wait for finish."""
    process = subprocess.Popen(
        [
            "pip",
            "install",
            "--target={}".format(DEFAULT_MODULE_DEPS_PATH),
            "--ignore-installed",
            "-r",
            requirements_path,
        ],
        shell=False,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    for output in process.communicate():
        if output != "":
            for line in output.splitlines():
                _LOGGER.debug(str(line).strip())
    process.wait()


# Traceback (FileNotFoundError)
INFO opsdroid: ========================================
INFO opsdroid: Started application
INFO opsdroid: ========================================
INFO opsdroid: You can customise your opsdroid by modifying your configuration.yaml
INFO opsdroid: Read more at: http://opsdroid.readthedocs.io/#configuration
INFO opsdroid: Watch the Get Started Videos at: http://bit.ly/2fnC0Fh
INFO opsdroid: Install Opsdroid Desktop at:
https://github.com/opsdroid/opsdroid-desktop/releases
INFO opsdroid: ========================================
WARNING opsdroid.loader: No databases in configuration.
Traceback (most recent call last):
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/__main__.py", line 140, in <module>
init()
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/__main__.py", line 137, in init
main()
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/__main__.py", line 130, in main
opsdroid.start_loop()
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/core.py", line 134, in start_loop
self.loader.load_modules_from_config(self.config)
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/loader.py", line 222, in load_modules_from_config
skills = self._load_modules('skill', config['skills'])
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/loader.py", line 271, in _load_modules
self._install_module(config)
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/loader.py", line 317, in _install_module
"/requirements.txt")
File "/Users/fabiorosado/Documents/GitHub/opsdroid/opsdroid/loader.py", line 112, in pip_install_deps
stderr=subprocess.PIPE)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'pip'
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 511, in __del__
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/unix_events.py", line 65, in close
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/unix_events.py", line 146, in remove_signal_handler
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

# Fixed code
def pip_install_deps(requirements_path):
    """Pip install a requirements.txt file and wait for finish."""
    process = None
    command = [
        "pip",
        "install",
        "--target={}".format(DEFAULT_MODULE_DEPS_PATH),
        "--ignore-installed",
        "-r",
        requirements_path,
    ]

    try:
        process = subprocess.Popen(
            command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )

    except FileNotFoundError:
        _LOGGER.debug(
            "Couldn't find the command 'pip', trying again with command 'pip3'"
        )

    try:
        command[0] = "pip3"
        process = subprocess.Popen(
            command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
    except FileNotFoundError:
        _LOGGER.debug(
            "Couldn't find the command 'pip3', install of %s will be skipped.",
            str(requirements_path),
        )

    if not process:
        raise OSError("Pip and pip3 not found, exiting...")

    for output in process.communicate():
        if output != "":
            for line in output.splitlines():
                _LOGGER.debug(str(line).strip())

    process.wait()
    return True