# Buggy code
def install_jupyter_hook(root=None):
    """Make xonsh available as a Jupyter kernel."""
    if not HAVE_JUPYTER:
        print("Could not install Jupyter kernel spec, please install Jupyter/IPython.")
        return
    spec = {
        "argv": [
            sys.executable,
            "-m",
            "xonsh.jupyter_kernel",
            "-f",
            "{connection_file}",
        ],
        "display_name": "Xonsh",
        "language": "xonsh",
        "codemirror_mode": "shell",
    }
    with TemporaryDirectory() as d:
        os.chmod(d, 0o755)  # Starts off as 700, not user readable
        if sys.platform == "win32":
            # Ensure that conda-build detects the hard coded prefix
            spec["argv"][0] = spec["argv"][0].replace(os.sep, os.altsep)
        with open(os.path.join(d, "kernel.json"), "w") as f:
            json.dump(spec, f, sort_keys=True)
        if "CONDA_BUILD" in os.environ:
            root = sys.prefix
            if sys.platform == "win32":
                root = root.replace(os.sep, os.altsep)
        print("Installing Jupyter kernel spec...")
        KernelSpecManager().install_kernel_spec(
            d, "xonsh", user=("--user" in sys.argv), replace=True, prefix=root
        )


# Traceback (FileNotFoundError)
Exception:
Traceback (most recent call last):
File "/home/nejl/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/home/nejl/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/home/nejl/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pip/req/req_set.py", line 732, in install
**kwargs
File "/home/nejl/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pip/req/req_install.py", line 928, in install
with open(inst_files_path, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'home/nejl/.pyenv/versions/3.5.1/lib/python3.5/site-packages/xonsh-0.2.7-py3.5.egg-info/installed-files.txt'

# Fixed code
def install_jupyter_hook(prefix=None, root=None):
    """Make xonsh available as a Jupyter kernel."""
    if not HAVE_JUPYTER:
        print("Could not install Jupyter kernel spec, please install Jupyter/IPython.")
        return
    spec = {
        "argv": [
            sys.executable,
            "-m",
            "xonsh.jupyter_kernel",
            "-f",
            "{connection_file}",
        ],
        "display_name": "Xonsh",
        "language": "xonsh",
        "codemirror_mode": "shell",
    }
    with TemporaryDirectory() as d:
        os.chmod(d, 0o755)  # Starts off as 700, not user readable
        if sys.platform == "win32":
            # Ensure that conda-build detects the hard coded prefix
            spec["argv"][0] = spec["argv"][0].replace(os.sep, os.altsep)
        with open(os.path.join(d, "kernel.json"), "w") as f:
            json.dump(spec, f, sort_keys=True)
        if "CONDA_BUILD" in os.environ:
            prefix = sys.prefix
            if sys.platform == "win32":
                prefix = prefix.replace(os.sep, os.altsep)
        user = "--user" in sys.argv
        print("Installing Jupyter kernel spec:")
        print("  root: {0!r}".format(root))
        print("  prefix: {0!r}".format(prefix))
        print("  as user: {0}".format(user))
        KernelSpecManager().install_kernel_spec(
            d, "xonsh", user=user, replace=True, prefix=prefix
        )