3

通过 pip( pip install pipenv) 安装时,在 zsh shell 上找不到命令pipenv

如果通过brew:安装它brew install pipenv,然后运行pipenv shell,出现错误

Loading .env environment variables...
Launching subshell in virtual environment...
Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/cli/command.py", line 429, in shell
    do_shell(
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/core.py", line 2387, in do_shell
    shell.fork_compat(*fork_args)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/shells.py", line 106, in fork_compat
    c = pexpect.spawn(self.cmd, ["-i"], dimensions=(dims.lines, dims.columns))
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/pexpect/pty_spawn.py", line 205, in __init__
    self._spawn(command, args, preexec_fn, dimensions)
  File "/usr/local/Cellar/pipenv/2020.11.15/libexec/lib/python3.9/site-packages/pipenv/vendor/pexpect/pty_spawn.py", line 276, in _spawn
    raise ExceptionPexpect('The command was not found or was not ' +
pipenv.vendor.pexpect.exceptions.ExceptionPexpect: The command was not found or was not executable: /use/bin/zsh.

没有路径命名/use/bin/zsh。为什么不稳定?

外壳路径是

echo $SHELL
/bin/zsh
4

1 回答 1

3

你问了两个问题,真的。我将在下面的单独部分中回答每个问题:

如何修复该错误

Loading .env environment variables...
...
The command was not found or was not executable: /use/bin/zsh.

看起来在你的.env文件中,你有PIPENV_SHELL=/use/bin/zsh. 这是不正确的。相反,它应该是

PIPENV_SHELL=/bin/zsh

甚至简单地

PIPENV_SHELL=zsh

或者您也可以将其删除。然后pipenv shell将简单地使用与您调用它相同的 shell。

如何pipenv在 macOS上正确安装

在 macOS上安装的正确方法pipenv有点复杂,但如果您不想在升级 Python 版本时遇到问题,这是唯一的方法:

  1. 撤消到目前为止所做的事情:
    % pip uninstall pipenv
    % brew uninstall pipenv
    
  2. 将以下内容添加到您的.zshrc文件中:
    eval "$( brew shellenv )"
    export PYENV_VERSION=3.9.5  # Set your preferred Python version.
    export PYENV_ROOT=~/.pyenv
    export PIPX_BIN_DIR=~/.local/bin
    export -U PATH path         # -U eliminates duplicates
    path=( 
        $PIPX_BIN_DIR
        $PYENV_ROOT/{bin,shims} 
        $path
    )
    
  3. 打开一个新的终端窗口(使上述更改生效)并执行以下操作:
    % brew install pyenv
    % pyenv install $PYENV_VERSION # Install your preferred Python.
    % pyenv global $PYENV_VERSION  # Make it your default Python.
    % pip install -U pip           # Update pip.
    % pip install -U --user pipx   # Install pipx into ~/.local/bin
    % pipx install pipenv          # pipx is like brew but for Python.
    
  4. 将以下内容添加到您的.zshrc文件中:
    eval "$( pyenv init - )"
    eval "$( pip completion --zsh )"
    eval "$( register-python-argcomplete pipx )"
    eval "$( pipenv --completion )"
    
  5. 重新启动您的 shell(通过键入exec zsh或打开一个新的终端窗口)以使上述内容生效。
于 2021-05-28T12:23:20.860 回答