问题
I have been using pyenv
for managing python versions and virtual environments on my mac for some time now.
Recently I reinstalled pyenv
and since then on every pyenv
command I try to run, I get the following error
/usr/local/bin/pyenv:94: command not found: shopt
My default shell is the latest MacOS
's default shell i.e. zsh
.
On searching for the fix, I found out it has something to do with bash
interfering with the zsh
.
My default shell is zsh
in settings, the contents of ~/.bash_profile
, /etc/profile
& /etc/bashrc
are all commented out but I am still having the issue.
My OS Verion is: 10.15.4
.
I tried reinstalling pyenv
as well but I am getting the same error.
I am unable to run ANY pyenv
related command.
Edit 1
I already have these lines in my .zshrc
as per the documentation, but as you can see, even this run a command pyenv root
and this gives me the same shopt
error.
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$(pyenv root)/shims:$(pyenv root)/completions/pyenv.zsh:$PATH"
Edit 2
Run
env
and add the output in your question
TMPDIR=/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/
XPC_FLAGS=0x0
TERM_PROGRAM_VERSION=433
TERM_PROGRAM=Apple_Terminal
XPC_SERVICE_NAME=0
TERM_SESSION_ID=55A65E3A-9B71-4C8A-81B8-0170EEAE3DCE
TERM=xterm-256color
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.j6zkqCw6Of/Listeners
SHELL=/bin/zsh
HOME=/Users/abc
LOGNAME=abc
USER=abc
PATH=/usr/local/opt/openssl@1.1/bin:/Users/saadali/Library/Python/3.7/bin:/usr/local/Cellar/postgresql@9.6/9.6.16/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/abc/bin:/usr/local/opt/rabbitmq/sbin
SHLVL=1
PYTHONPATH=
LANGUAGE=en_US.UTF-8
port=
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
CPPFLAGS=-I/usr/local/opt/openssl@1.1/include
LDFLAGS=-L/usr/local/opt/openssl@1.1/lib
CFLAGS=-I/usr/local/opt/openssl@1.1/include
LANG=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
_=/usr/bin/env
Edit 3
Please read this chat first before recommending to try something, as I might have already tried it. Chat starts at Apr 29 02:01 UTC +5
and then moves to a thread.
Edit 4
After setting PYENV_DEBUG=1
, here the output
(vmds) saadali@A006-00276 ~ :~$ pyenv
+ [:22] enable -f /../libexec/pyenv-realpath.dylib realpath
+ [:29] [ -z '' ']'
+ [:31] READLINK=+ [:31] type -p greadlink readlink
+ [:31] READLINK=+ [:31] head -1
+ [:31] READLINK='greadlink not found'
+ [:32] [ -n 'greadlink not found' ']'
+ [:57] [ -z '' ']'
+ [:58] PYENV_ROOT=/Users/abc/.pyenv
+ [:62] export PYENV_ROOT
+ [:65] [ -z '' ']'
+ [:66] [ -n '' ']'
+ [:82] [ -z '' ']'
+ [:83] PYENV_DIR=/Users/abc
+ [:86] [ ! -d /Users/abc ']'
+ [:86] [ ! -e /Users/abc ']'
+ [:90] PYENV_DIR=+ [:90] cd /Users/abc
+ [:90] echo /Users/abc
+ [:90] PYENV_DIR=/Users/abc
+ [:91] export PYENV_DIR
+ [:94] shopt -s nullglob
/usr/local/bin/pyenv:94: command not found: shopt
回答1:
According to your info and comments it seems your issue has 3 causes working hand in hand:
- pyenv is a bash (and bash-only) script with a shebang line
#!/usr/bin/env bash
/usr/local/bin
comes before/usr/bin
or/bin
in your PATH, so executables therein are picked up first by/usr/bin/env
(desired behaviour, especially when using homebrew)/usr/local/bin/bash
is symlinked to/bin/zsh
!?!
So in the end you are running pyenv with zsh, which, albeit being a close replacement for bash, doesn't know about shopt and therefore chokes. I don't know why the symlink is in place, but it shouldn't, because zsh is not a fully compatible drop-in replacement for bash.
I'd suggest to
(in case you are using homebrew)
Check if you have/hadbash
installed through homebrew (which was later somehow replaced by a symlink to zsh):# shows only top-level packages (directly installed) brew leaves # shows *all* packages with dependency tree brew deps --tree --installed
And uninstall bash if not required anymore (which should then remove
/usr/local/bin/bash
).Either delete or at least rename the culprit:
mv /usr/local/bin/bash /usr/local/bin/bash_link_to_zsh
Or, if some program requires
/usr/local/bin/bash
to be in place, just have it point to/bin/bash
.
来源:https://stackoverflow.com/questions/61478739/pyenv-giving-shopt-command-not-found-error-on-macos