Repository: pypa/pipenv

Issue:
pipenv failed in virtualenv
pipenv, version 2018.10.9

(create a new virtualenv and install pipenv)
$ pipenv install ipython
Installing ipython…
(....something does not matter)
Adding ipython to Pipfile's [packages]…
Pipfile.lock (17b797) out of date, updating to (8fdd10)…
Locking [dev-packages] dependencies…
Traceback (most recent call last):
  File "/home/craynic/.virtualenvs/test2/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/cli/command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/core.py", line 1950, in do_install
    skip_lock=skip_lock,
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/core.py", line 1242, in do_init
    pypi_mirror=pypi_mirror,
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/core.py", line 1034, in do_lock
    pypi_mirror=pypi_mirror,
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/utils.py", line 355, in venv_resolve_deps
    escape_grouped_arguments(which("python", allow_global=allow_global)),
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/site-packages/pipenv/core.py", line 109, in which
    if not location and os.path.exists(location):
  File "/home/craynic/.virtualenvs/test2/lib/python3.7/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType


Discussion:

Resolving patch:
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -106,7 +106,7 @@ def spinner():
 def which(command, location=None, allow_global=False):
     if not allow_global and location is None:
         location = project.virtualenv_location or os.environ.get("VIRTUAL_ENV", "")
-    if not location and os.path.exists(location):
+    if not (location and os.path.exists(location)):
         raise RuntimeError("virtualenv not created nor specified")
     if not allow_global:
         if os.name == "nt":


Test patch: