Repository: pre-commit/pre-commit

Issue:
Not working on macOS Sierra?
Attempting to utilize a collection of hooks from the default repo, I get the following:

```
An unexpected error has occurred: CalledProcessError: Command: ('/Users/amcgregor/Projects/marrow/.venv/bin/python3', '-m', 'virtualenv', '/Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default')
Return code: 100
Expected return code: 0
Output: 
    Using base prefix '/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.5'
    New python executable in /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python3
    Also creating executable in /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python
    ERROR: The executable /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python3 is not functioning
    ERROR: It thinks sys.prefix is '/Library/Frameworks/Python.framework/Versions/3.5' (should be '/Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default')
    ERROR: virtualenv is not compatible with this system or executable

Errors: (none)

Traceback (most recent call last):
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/error_handler.py", line 47, in error_handler
    yield
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/main.py", line 157, in main
    return run(runner, args)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/commands/run.py", line 212, in run
    return _run_hooks(repo_hooks, args, write, environ)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/staged_files_only.py", line 63, in staged_files_only
    yield
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/commands/run.py", line 195, in run
    repo_hooks = list(get_repo_hooks(runner))
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/commands/run.py", line 141, in get_repo_hooks
    for repo in runner.repositories:
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/cached_property.py", line 26, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/runner.py", line 47, in repositories
    repository.require_installed()
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/repository.py", line 117, in require_installed
    self.install()
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/repository.py", line 187, in install
    self.additional_dependencies[language_name][language_version],
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/languages/python.py", line 78, in install_environment
    ('pip', 'install', '.') + additional_dependencies,
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/util.py", line 58, in clean_path_on_failure
    yield
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/languages/python.py", line 74, in install_environment
    repo_cmd_runner.run(venv_cmd)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/prefixed_command_runner.py", line 39, in run
    return cmd_output(*replaced_cmd, __popen=self.__popen, **kwargs)
  File "/Users/amcgregor/Projects/marrow/.venv/lib/python3.5/site-packages/pre_commit/util.py", line 189, in cmd_output
    returncode, cmd, retcode, output=(stdout, stderr),
pre_commit.util.CalledProcessError: Command: ('/Users/amcgregor/Projects/marrow/.venv/bin/python3', '-m', 'virtualenv', '/Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default')
Return code: 100
Expected return code: 0
Output: 
    Using base prefix '/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.5'
    New python executable in /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python3
    Also creating executable in /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python
    ERROR: The executable /Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default/bin/python3 is not functioning
    ERROR: It thinks sys.prefix is '/Library/Frameworks/Python.framework/Versions/3.5' (should be '/Users/amcgregor/.pre-commit/repofu57ylaa/py_env-default')
    ERROR: virtualenv is not compatible with this system or executable

Errors: (none)
```

Using the Python.org-provided Python 3.5 installer package.  I'm already within a virtual environment at the point of execution.



Discussion:
Thanks for the report! 

Does `virtualenv venv` give the same error message? What version of virtualenv do you have installed alongside pre-commit? 

Ahah! I am able to reproduce this outside pre-commit (on el capitan no less), though I think I can fix it inside pre-commit.  I'll cook up a feature branch!  It seems to be caused by the mixing of stdlib `venv` (previously `pyvenv`) and the slightly more maintained `virtualenv` project.

Here's my minimal reproduction btw:

```
$ python3.5 -m venv venv35
$ . venv35/bin/activate
(venv35) $ pip install virtualenv
Collecting virtualenv
  Using cached virtualenv-15.0.3-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.0.3
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv35) $ virtualenv venv2
Using base prefix '/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.5'
Overwriting /Users/asottile/workspace/pre-commit/venv2/lib/python3.5/orig-prefix.txt with new content
New python executable in /Users/asottile/workspace/pre-commit/venv2/bin/python3.5
Not overwriting existing python script /Users/asottile/workspace/pre-commit/venv2/bin/python (you must use /Users/asottile/workspace/pre-commit/venv2/bin/python3.5)
ERROR: The executable /Users/asottile/workspace/pre-commit/venv2/bin/python3.5 is not functioning
ERROR: It thinks sys.prefix is '/Library/Frameworks/Python.framework/Versions/3.5' (should be '/Users/asottile/workspace/pre-commit/venv2')
ERROR: virtualenv is not compatible with this system or executable
```

However, I can work around this it seems:

```
(venv35) $ virtualenv venv2 -p "$(python -c 'import os, sys; print(os.path.realpath(sys.executable))')"
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.5'
Overwriting /Users/asottile/workspace/pre-commit/venv2/lib/python3.5/orig-prefix.txt with new content
New python executable in /Users/asottile/workspace/pre-commit/venv2/bin/python3.5
Not overwriting existing python script /Users/asottile/workspace/pre-commit/venv2/bin/python (you must use /Users/asottile/workspace/pre-commit/venv2/bin/python3.5)
Installing setuptools, pip, wheel...done.
```

Awesome, thanks!  Apologies for not noticing your initial reply (got lost in a bunch of Travis traffic after I pushed updates to way, way too many repos and branches at the same time…)

With a virtualenv installed system-wide (`/usr/local/bin/virtualenv`, 15.0.3, running under macOS-provided Python 2.7) and virtualenv installed within my venv (`$VIRTUAL_ENV/bin/virtualenv`, 15.0.3, running under venv-provided 3.5.2 from official Python.org `.pkg`) running `virtualenv foo` does, in fact, explode gloriously.

Edited to add: running `virtualenv foo` outside of my existing venv works fine.  (Defaulting to `--python=python2.7`.)  Explicitly running `virtualenv --python=python3.5 foo` also works fine when outside of an existing environment.

Makes sense! I recognize you from contributions on dahlia/libsass-python :)


Resolving patch:
diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
--- a/pre_commit/languages/python.py
+++ b/pre_commit/languages/python.py
@@ -71,6 +71,8 @@ def install_environment(
         ]
         if version != 'default':
             venv_cmd.extend(['-p', norm_version(version)])
+        else:
+            venv_cmd.extend(['-p', os.path.realpath(sys.executable)])
         repo_cmd_runner.run(venv_cmd)
         with in_env(repo_cmd_runner, version):
             helpers.run_setup_cmd(


Test patch: