首页 > 解决方案 > 在 macOS 上“pipenv shell”=> bash:update_terminal_cwd:找不到命令

问题描述

试图让 pipenv 在 macOS 10.14.4 上工作。

$cat Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
numpy = "==1.14.1"

[requires]
python_version = "3.6.8"

这有效:

 $pipenv --rm
Removing virtualenv (/Users/me/.local/share/virtualenvs/blah-zeMrhw5d)…

这有效:

 $pipenv install
Creating a virtualenv for this project…
Pipfile: /Users/me/mypath/Pipfile
Using /Users/me/.pyenv/versions/3.6.8/bin/python3 (3.6.8) to create virtualenv…
⠏ Creating virtual environment...Using base prefix '/Users/me/.pyenv/versions/3.6.8'
New python executable in /Users/me/.local/share/virtualenvs/blah-zeMrhw5d/bin/python3
Also creating executable in /Users/me/.local/share/virtualenvs/blah-zeMrhw5d/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Users/me/.pyenv/versions/3.6.8/bin/python3

✔ Successfully created virtual environment! 
Virtualenv location: /Users/me/.local/share/virtualenvs/blah-zeMrhw5d
Pipfile.lock (7fd81f) out of date, updating to (89a067)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success! 
Updated Pipfile.lock (7fd81f)!
Installing dependencies from Pipfile.lock (7fd81f)…
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:02
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

这不起作用:

$pipenv shell
Launching subshell in virtual environment…
 . /Users/alexryan/.local/share/virtualenvs/cabin_monitoring-zeMrhw5d/bin/activate
bash: update_terminal_cwd: command not found
$ . /Users/alexryan/.local/share/virtualenvs/cabin_monitoring-zeMrhw5d/bin/activate
bash: update_terminal_cwd: command not found
(cabin_monitoring) $

每次我在此环境中发出命令时都会引发这些错误。

(blah)  >ls -lF
total 12
-rw-r--r--  1 alexryan staff  159 Apr 30 14:49 Pipfile
-rw-r--r--  1 alexryan staff 2683 Apr 30 14:50 Pipfile.lock
...
bash: update_terminal_cwd: command not found
(blah) $
(cabin_monitoring)  >

来自https://apple.stackexchange.com/a/139808/91429我看到update_terminal_cwd已定义/etc/bashrc

我可以source /etc/bashrc让这个错误消失,但这样做会打乱我的提示,因此我在虚拟环境中不再明显。

(blah) $source /etc/bashrc
hostname:blah me$

确保pipenv shell在 macos 上正常工作的最佳方法是什么?

更新

我正在使用 pyenv 来指定我希望使用的 python 版本,因为 pipenv 似乎需要这个。

我通过安装 pyenvcurl https://pyenv.run | bash并按要求添加了这些行~/.bashrc

# Load pyenv automatically by adding
# the following to ~/.bashrc:

export PATH="/Users/me/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

并确保它~/.bashrc是这样调用的~/.bash_profile(因为显然pipenv shell 是一个非登录外壳)。

[[ -f ~/.bashrc ]] && source ~/.bashrc

pyenv 在安装了多个版本的 python 时工作正常。

标签: pipenv

解决方案


推荐阅读