Pipenv: Misleading error message when Pipfile is removed

Created on 9 Oct 2018  Â·  8Comments  Â·  Source: pypa/pipenv

Issue description

When I remove the file Pipfile.lock it fails with a traceback:

...
  File "/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv/utils.py", line 355, in venv_resolve_deps
    escape_grouped_arguments(which("python", allow_global=allow_global)),
  File "/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv/core.py", line 109, in which
    if not location and os.path.exists(location):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/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

When I remove Pipfile it fails with another traceback:

  File "/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv/core.py", line 320, in ensure_pipfile
    project.create_pipfile(python=python)
  File "/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv/project.py", line 627, in create_pipfile
    config_parser = ConfigOptionParser(name=self.name)
  File "/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv/project.py", line 219, in name
    self._name = self.pipfile_location.split(os.sep)[-2]
AttributeError: 'NoneType' object has no attribute 'split'

Expected result

I would expect a proper error message that some required file is missing. I would expect such behavior from a high-level beginner-friendly software :)

In case of the lock file I would expect a new lock file to be created (similar to npm, for example).

In the second case, the error happens inside create_pipfile, so maybe it is trying to create the pipflle, but still fails. So maybe it's an another issue?


$ pipenv --support

Pipenv version: '2018.10.9'

Pipenv location: '/Users/messa/code/gh/naucse.python.cz/myvenv/lib/python3.7/site-packages/pipenv'

Python location: '/Users/messa/code/gh/naucse.python.cz/myvenv/bin/python'

Python installations found:

  • 3.7.0: /opt/local/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
  • 3.7.0: /opt/local/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
  • 3.6.6: /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
  • 3.6.6: /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
  • 3.5.6: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5m
  • 3.5.6: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
  • 2.7.15: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  • 2.7.10: /usr/bin/python
  • 2.7.10: /usr/bin/pythonw
  • 2.7.10: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.7.0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '17.7.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT '
                     '2018; root:xnu-4570.71.2~1/RELEASE_X86_64',
 'python_full_version': '3.7.0',
 'python_version': '3.7',
 'sys_platform': 'darwin'}

System environment variables:

  • LANG
  • XPC_FLAGS
  • DISPLAY
  • OLDPWD
  • TERM_SESSION_ID
  • COLORTERM
  • __CF_USER_TEXT_ENCODING
  • ITERM_SESSION_ID
  • SSH_AUTH_SOCK
  • VIRTUAL_ENV
  • USER
  • PWD
  • HOME
  • TERM_PROGRAM
  • TERM_PROGRAM_VERSION
  • Apple_PubSub_Socket_Render
  • ITERM_PROFILE
  • TMPDIR
  • XPC_SERVICE_NAME
  • TERM
  • SHELL
  • SHLVL
  • COLORFGBG
  • LOGNAME
  • PATH
  • PS1
  • _
  • PYTHONDONTWRITEBYTECODE
  • PIP_SHIMS_BASE_MODULE
  • PIP_PYTHON_PATH

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /Users/messa/code/gh/naucse.python.cz/myvenv/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/local/libexec/gnubin
  • SHELL: /bin/bash
  • LANG: cs_CZ.UTF-8
  • PWD: /Users/messa/code/gh/naucse.python.cz
  • VIRTUAL_ENV: /Users/messa/code/gh/naucse.python.cz/myvenv

Type Regression

All 8 comments

I would expect such behavior from a high-level beginner-friendly software :)

Yes, software has bugs in it. This one is maintained by usually 1-2 volunteers at most. Please try to keep the conversation productive.

When you remove pipfile.lock, _what_ fails? You removed your lockfile and then ran what command specifically? It's not clear what happened here from the snipped output

I am running into a similar problem when trying to import from a requirements file; it seems that because the Pipfile.lock is out of date it tries to remove it and fails.

PIPENV_VENV_IN_PROJECT=true pipenv install --three -r path/to/requirements.txt

Yields:

Pipfile.lock (948a23) out of date, updating to (799c69)…
Locking [dev-packages] dependencies…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli/command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1950, in do_install
    skip_lock=skip_lock,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1242, in do_init
    pypi_mirror=pypi_mirror,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1034, in do_lock
    pypi_mirror=pypi_mirror,
  File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 355, in venv_resolve_deps
    escape_grouped_arguments(which("python", allow_global=allow_global)),
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 109, in which
    if not location and os.path.exists(location):
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

This only seems to be a problem if the virtualenv is on. Thanks for the hard work maintaining this package!

I'm seeing this issue when using pipenv inside tox. I think the test at line 109 of core.py is just wrong, if not location fails then there's no point checking if it exists. Perhaps it should be:

if location and not os.path.exists(location)

Looks like this has been fixed in b06ba8b3b28d78753211608aef385e63b907d0bd

The following workaround works for tox, basically pin the versions of pipenv and pip you use in your deps:

deps =
    pipenv==2018.7.1
    pip==18.0

Confirming that it works as expected when installed from current master branch (pip install -U https://github.com/pypa/pipenv/archive/d3da491e2e5516497d8c8d7a1e963c74c947692a.zip). When I remove Pipfile.lock and run pipenv install, it doesn't fail with exception and recreates Pipfile.lock as expected. The same even for removing Pipfile. Perfect :)

I would expect such behavior from a high-level beginner-friendly software :)

Yes, software has bugs in it. This one is maintained by usually 1-2 volunteers at most. Please try to keep the conversation productive.

I was just explaining why I think the output should be something better than a traceback. Maybe the explanation was not in the best way possible - English is not my native language, and I just wanted somebody to notice and to start discussion what to do with it etc. Also I guess the timing was not the best either :)

When you remove pipfile.lock, _what_ fails? You removed your lockfile and then ran what command specifically? It's not clear what happened here from the snipped output

I'm sorry for that. I ran pipenv install. It should have been in the issue description.

In addition to the fixes, I also added some significant cleanup and exception handling improvements which will be out this release, so hopefully that gets us on a more sustainable path to having cleaner error messaging.

Thanks for submitting the issue, sorry for the bugs!

Was this page helpful?
0 / 5 - 0 ratings