coveralls: ## Pull Request Test Coverage Report for [Build 174](https://coveralls.io/builds/19710438)

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* **7** unchanged lines in **1** file lost coverage.
* Overall coverage increased (+**0.2%**) to **76.429%**

---


|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [.tox/py36/lib/python3.6/site-packages/shiv/cli.py](https://coveralls.io/builds/19710438/source?filename=.tox%2Fpy36%2Flib%2Fpython3.6%2Fsite-packages%2Fshiv%2Fcli.py#L48) | 7 | 87.84% |
<!-- | **Total:** | **7** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/19710438/badge)](https://coveralls.io/builds/19710438) |
| :-- | --: |
| Change from base [Build 172](https://coveralls.io/builds/19660274): |  0.2% |
| Covered Lines: | 214 |
| Relevant Lines: | 280 |

---
##### 💛  - [Coveralls](https://coveralls.io)

sixninetynine: will need to get on my windows box to poke at the test failures later (that darn `.exe` extension)
diff --git a/README.md b/README.md
index 831be3b..656dfb2 100644
--- a/README.md
+++ b/README.md
@@ -69,8 +69,8 @@ pip install shiv
 You can even create a pyz _of_ shiv _using_ shiv!
 
 ```sh
-python3 -m venv shiv
-source shiv/bin/activate
+python3 -m venv .
+source bin/activate
 pip install shiv
 shiv -c shiv -o shiv shiv
 ```
diff --git a/src/shiv/bootstrap/__init__.py b/src/shiv/bootstrap/__init__.py
index 6c2989b..52558a0 100644
--- a/src/shiv/bootstrap/__init__.py
+++ b/src/shiv/bootstrap/__init__.py
@@ -123,7 +123,7 @@ def bootstrap():
         mod = import_string(env.entry_point)
         try:
             sys.exit(mod())
-        except TypeError as e:
+        except TypeError:
             # catch "<module> is not callable", which is thrown when the entry point's
             # callable shares a name with it's parent module
             # e.g. "from foo.bar import bar; bar()"
diff --git a/src/shiv/cli.py b/src/shiv/cli.py
index 27010cc..ec97dea 100644
--- a/src/shiv/cli.py
+++ b/src/shiv/cli.py
@@ -26,7 +26,7 @@ from .constants import (
     NO_ENTRY_POINT,
 )
 
-__version__ = '0.0.36'
+__version__ = "0.0.36"
 
 # This is the 'knife' emoji
 SHIV = u"\U0001F52A"
@@ -42,6 +42,7 @@ def find_entry_point(site_packages: Path, console_script: str) -> str:
     :param site_packages: A path to a site-packages directory on disk.
     :param console_script: A console_script string.
     """
+
     config_parser = ConfigParser()
     config_parser.read(site_packages.rglob("entry_points.txt"))
     return config_parser["console_scripts"][console_script]
@@ -55,18 +56,52 @@ def copy_bootstrap(bootstrap_target: Path) -> None:
 
     :param bootstrap_target: The temporary directory where we are staging pyz contents.
     """
+
     for bootstrap_file in importlib_resources.contents(bootstrap):
         if importlib_resources.is_resource(bootstrap, bootstrap_file):
             with importlib_resources.path(bootstrap, bootstrap_file) as f:
                 shutil.copyfile(f.absolute(), bootstrap_target / f.name)
 
 
+def _interpreter_path(append_version: bool = False) -> str:
+    """A function to return the path to the current Python interpreter.
+
+    Even when inside a venv, this will return the interpreter the venv was created with.
+
+    """
+
+    base_dir = Path(getattr(sys, "real_prefix", sys.base_prefix)).resolve()
+    sys_exec = Path(sys.executable)
+    name = sys_exec.stem
+    suffix = sys_exec.suffix
+
+    if append_version:
+        name += str(sys.version_info.major)
+
+    name += suffix
+
+    try:
+        return str(next(iter(base_dir.rglob(name))))
+
+    except StopIteration:
+
+        if not append_version:
+            # If we couldn't find an interpreter, it's likely that we looked for
+            # "python" when we should've been looking for "python3"
+            # so we try again with append_version=True
+            return _interpreter_path(append_version=True)
+
+        # If we were still unable to find a real interpreter for some reason
+        # we fallback to the current runtime's interpreter
+        return sys.executable
+
+
 @click.command(
     context_settings=dict(
         help_option_names=["-h", "--help", "--halp"], ignore_unknown_options=True
     )
 )
-@click.version_option(version=__version__, prog_name='shiv')
+@click.version_option(version=__version__, prog_name="shiv")
 @click.option("--entry-point", "-e", default=None, help="The entry point to invoke.")
 @click.option(
     "--console-script", "-c", default=None, help="The console_script to invoke."
@@ -103,7 +138,8 @@ def main(
     Shiv is a command line utility for building fully self-contained Python zipapps
     as outlined in PEP 441, but with all their dependencies included!
     """
-    quiet = "-q" in pip_args or '--quiet' in pip_args
+
+    quiet = "-q" in pip_args or "--quiet" in pip_args
 
     if not quiet:
         click.secho(" shiv! " + SHIV, bold=True)
@@ -158,8 +194,8 @@ def main(
         # create the zip
         builder.create_archive(
             Path(working_path),
-            target=Path(output_file),
-            interpreter=python or sys.executable,
+            target=Path(output_file).expanduser(),
+            interpreter=python or _interpreter_path(),
             main="_bootstrap:bootstrap",
             compressed=compressed,
         )

The "create a pyz of shiv using shiv" example doesn't work
As written, the example leaves the shiv pyz file with a shebang pointing at the (presumably temporary) virtual environment used to build it.

The example should probably include a `-p "/usr/bin/env python3"` argument to specify an explicit interpreter.

Actually, given that shiv pyz files are self-contained, there's no real benefit to them ever having shebangs that refer to a virtualenv - maybe it would be worth making the default shebang `/usr/bin/env python3`, or at least locate the "base" Python interpreter for a virtualenv - which can be done as

```python
Path(getattr(sys, 'real_prefix', sys.base_prefix)) / Path(sys.executable).relative_to(sys.prefix)
```
diff --git a/test/test_cli.py b/test/test_cli.py
index 30cd78b..3e469cc 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -8,7 +8,7 @@ import pytest
 
 from click.testing import CliRunner
 
-from shiv.cli import main
+from shiv.cli import main, _interpreter_path
 from shiv.constants import DISALLOWED_PIP_ARGS, NO_PIP_ARGS_OR_SITE_PACKAGES, NO_OUTFILE, BLACKLISTED_ARGS
 
 
@@ -31,6 +31,11 @@ class TestCLI:
         assert result.exit_code == 1
         assert strip_header(result.output) == NO_OUTFILE
 
+    def test_find_interpreter(self):
+        interpreter = _interpreter_path()
+        assert Path(interpreter).exists()
+        assert Path(interpreter).is_file()
+
     @pytest.mark.parametrize("arg", [arg for tup in BLACKLISTED_ARGS.keys() for arg in tup])
     def test_blacklisted_args(self, runner, arg):
         result = runner(['-o', 'tmp', arg])

pip install -e .[dev]
parse_log_pytest
pytest
pytest mypy flake8
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
click==6.7
flake8==5.0.4
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
mccabe==0.7.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
mypy==0.971
mypy-extensions==1.0.0
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
-e git+https://github.com/linkedin/shiv.git@801db3717d3957c0b7e59e9cbd10ac4f714a0dfb#egg=shiv
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tomli==1.2.3
typed-ast==1.5.5
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: shiv
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - click==6.7
      - flake8==5.0.4
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - mccabe==0.7.0
      - mypy==0.971
      - mypy-extensions==1.0.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - tomli==1.2.3
      - typed-ast==1.5.5
prefix: /opt/conda/envs/shiv

test/test_bootstrap.py::TestBootstrap::test_various_imports test/test_bootstrap.py::TestBootstrap::test_is_zipfile test/test_bootstrap.py::TestBootstrap::test_argv0_is_not_zipfile test/test_bootstrap.py::TestBootstrap::test_cache_path test/test_bootstrap.py::TestBootstrap::test_first_sitedir_index test/test_bootstrap.py::TestEnvironment::test_overrides test/test_bootstrap.py::TestEnvironment::test_serialize test/test_builder.py::TestBuilder::test_file_prefix[/usr/bin/python-#!/usr/bin/python\n] test/test_builder.py::TestBuilder::test_file_prefix[/usr/bin/env test/test_builder.py::TestBuilder::test_file_prefix[/some/other/path/python test/test_builder.py::TestBuilder::test_binprm_error test/test_builder.py::TestBuilder::test_create_archive test/test_builder.py::TestBuilder::test_archive_permissions test/test_cli.py::TestCLI::test_no_args test/test_cli.py::TestCLI::test_no_outfile test/test_cli.py::TestCLI::test_find_interpreter test/test_cli.py::TestCLI::test_blacklisted_args[-t] test/test_cli.py::TestCLI::test_blacklisted_args[--target] test/test_cli.py::TestCLI::test_blacklisted_args[--editable] test/test_cli.py::TestCLI::test_blacklisted_args[-d] test/test_cli.py::TestCLI::test_blacklisted_args[--download] test/test_cli.py::TestCLI::test_blacklisted_args[--user] test/test_cli.py::TestCLI::test_blacklisted_args[--root] test/test_cli.py::TestCLI::test_blacklisted_args[--prefix] test/test_cli.py::TestCLI::test_hello_world[.---compile-pyc] test/test_cli.py::TestCLI::test_hello_world[.---no-compile-pyc] test/test_cli.py::TestCLI::test_hello_world[absolute-path---compile-pyc] test/test_cli.py::TestCLI::test_hello_world[absolute-path---no-compile-pyc] test/test_pip.py::test_clean_pip_env
src/shiv/bootstrap/__init__.py README.md src/shiv/cli.py
src/shiv/bootstrap/__init__.py README.md src/shiv/cli.py