试图让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似乎需要这样做。
我通过curl https://pyenv.run | bash
安装了pyenv,并根据要求将这些行添加到~/.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
is a nonlogin shell)。
[[ -f ~/.bashrc ]] && source ~/.bashrc
pyenv可以在安装多个版本的python的情况下正常工作。