pipenv: Completion is not working with zsh on macOS

Maybe this is related to #226 ?

$ pipsi install pipenv
Running virtualenv with interpreter /Users/markus/.local/venvs/pipsi/bin/python3.6
Using real prefix '/usr/local/var/pyenv/versions/3.6.1'
New python executable in /Users/markus/.local/venvs/pipenv/bin/python3.6
Also creating executable in /Users/markus/.local/venvs/pipenv/bin/python
Installing setuptools, pip, wheel...done.
Collecting pipenv
Collecting pew>=0.1.26 (from pipenv)
  Using cached pew-0.1.26-py2.py3-none-any.whl
Requirement already satisfied: pip in ./.local/venvs/pipenv/lib/python3.6/site-packages (from pipenv)
Collecting virtualenv (from pipenv)
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Collecting pythonz-bd>=1.10.2 (from pew>=0.1.26->pipenv)
  Using cached pythonz_bd-1.11.4-py3-none-any.whl
Collecting virtualenv-clone>=0.2.5 (from pew>=0.1.26->pipenv)
Requirement already satisfied: setuptools>=17.1 in ./.local/venvs/pipenv/lib/python3.6/site-packages (from pew>=0.1.26->pipenv)
Collecting resumable-urlretrieve; python_version == "3.6" (from pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Using cached resumable_urlretrieve-0.1.5-py2.py3-none-any.whl
Collecting requests (from resumable-urlretrieve; python_version == "3.6"->pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Downloading requests-2.18.2-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.7MB/s
Collecting certifi>=2017.4.17 (from requests->resumable-urlretrieve; python_version == "3.6"->pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Using cached certifi-2017.4.17-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests->resumable-urlretrieve; python_version == "3.6"->pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 3.4MB/s
Collecting idna<2.6,>=2.5 (from requests->resumable-urlretrieve; python_version == "3.6"->pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Using cached idna-2.5-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->resumable-urlretrieve; python_version == "3.6"->pythonz-bd>=1.10.2->pew>=0.1.26->pipenv)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: certifi, urllib3, idna, chardet, requests, resumable-urlretrieve, pythonz-bd, virtualenv, virtualenv-clone, pew, pipenv
Successfully installed certifi-2017.4.17 chardet-3.0.4 idna-2.5 pew-0.1.26 pipenv-5.1.2 pythonz-bd-1.11.4 requests-2.18.2 resumable-urlretrieve-0.1.5 urllib3-1.22 virtualenv-15.1.0 virtualenv-clone-0.2.6
  Linked script /Users/markus/.local/bin/pipenv
Done.
$ pipenv --version
pipenv, version 5.1.2
$ _PIPENV_COMPLETE=source pipenv
Traceback (most recent call last):
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click_completion.py", line 409, in get_auto_shell
    import psutil
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/psutil/__init__.py", line 136, in <module>
    from . import _psosx as _psplatform
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/psutil/_psosx.py", line 14, in <module>
    from . import _psutil_osx as cext
ImportError: cannot import name '_psutil_osx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/markus/.local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 692, in main
    _bashcomplete(self, prog_name, complete_var)
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click_completion.py", line 297, in _shellcomplete
    echo(get_code(prog_name=prog_name, env_name=complete_var))
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click_completion.py", line 387, in get_code
    shell = get_auto_shell()
  File "/Users/markus/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click_completion.py", line 415, in get_auto_shell
    raise click.UsageError("Please explicitly give the shell type or install the psutil package to activate the"
click.exceptions.UsageError: Please explicitly give the shell type or install the psutil package to activate the automatic shell detection.
$ _PIPENV_COMPLETE=source-zsh pipenv

#compdef pipenv
_pipenv() {
  eval $(env COMMANDLINE="${words[1,$CURRENT]}" _PIPENV_COMPLETE=complete-zsh  pipenv)
}
if [[ "$(basename ${(%):-%x})" != "_pipenv" ]]; then
  autoload -U compinit && compinit
  compdef _pipenv pipenv
fi

But it’s not completing anything …

$ eval $(_PIPENV_COMPLETE=source-zsh pipenv)
$ pipenv i<Tab>
-- file --
Applications/             Downloads/                Movies/                   VirtualBox\ VMs/

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

Ok, I found a workaround which "works for me"™️, but expects oh-my-zsh to be used:

pipenv --completion >> .oh-my-zsh/custom/pipenv_completion.zsh

All files there get auto-loaded on zsh startup. Bonus: It’s faster since pipenv does not need to be executed on shell startup. I’m sure there are standard/non-oh-my-zsh places that can be used instead, but my vanilla-zsh-fu is not strong enough for this.

Ooh, wait. I was forgetting to quote it on my Mac.

eval “$(_PIPENV_COMPLETE=source-zsh pipenv)”

… yields “basename: illegal option – z”

@tilgovi try removing the quotes …

That’s why I recommend installing pipenv w/ pipsi.