pyenv 在 macos 上给出 shopt 命令未找到错误 [英] pyenv giving shopt command not found error on macos

查看:28
本文介绍了pyenv 在 macos 上给出 shopt 命令未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在使用 pyenv 来管理我的 mac 上的 python 版本和虚拟环境.最近我重新安装了 pyenv,从那以后在我尝试运行的每个 pyenv 命令上,我都收到以下错误

/usr/local/bin/pyenv:94:找不到命令:shopt

我的默认 shell 是最新的 MacOS 的默认 shell,即 zsh.
在搜索修复程序时,我发现它与 bash 干扰 zsh 有关系.
我的默认shell是settings中的zsh~/.bash_profile的内容,/etc/profile &/etc/bashrc 都被注释掉了,但我仍然有这个问题.
我的操作系统版本是:10.15.4.
我也尝试重新安装 pyenv,但我遇到了同样的错误.

我无法运行任何 pyenv 相关命令.

编辑 1

根据文档,我的 .zshrc 中已经有这些行,但是正如您所看到的,即使这样也运行命令 pyenv root 并且这给了我相同的shopt 错误.

export PYENV_ROOT="$HOME/.pyenv"export PATH="$PYENV_ROOT/bin:$(pyenv root)/shims:$(pyenv root)/completions/pyenv.zsh:$PATH"

编辑 2

<块引用>

运行 env 并在您的问题中添加输出

TMPDIR=/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/XPC_FLAGS=0x0TERM_PROGRAM_VERSION=433TERM_PROGRAM=苹果_终端XPC_SERVICE_NAME=0TERM_SESSION_ID=55A65E3A-9B71-4C8A-81B8-0170EEAE3DCETERM=xterm-256colorSSH_AUTH_SOCK=/private/tmp/com.apple.launchd.j6zkqCw6Of/Listeners外壳=/bin/zsh主页=/用户/abc日志名=abc用户=abcPATH=/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/sbinSHLVL=1蟒蛇路径=LANGUAGE=en_US.UTF-8端口=LC_NUMERIC=en_US.UTF-8LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8LC_MONETARY=en_US.UTF-8LC_PAPER=en_US.UTF-8LC_NAME=en_US.UTF-8LC_ADDRESS=en_US.UTF-8LC_TELEPHONE=en_US.UTF-8LC_MEASUREMENT=en_US.UTF-8LC_IDENTIFICATION=en_US.UTF-8CPPFLAGS=-I/usr/local/opt/openssl@1.1/includeLDFLAGS=-L/usr/local/opt/openssl@1.1/libCFLAGS=-I/usr/local/opt/openssl@1.1/includeLANG=en_US.UTF-8LC_MESSAGES=en_US.UTF-8LC_ALL=en_US.UTF-8LC_CTYPE=en_US.UTF-8_=/usr/bin/env

编辑 3

请先阅读这个聊天,然后再推荐尝试,因为我可能已经尝试过了.聊天从 4 月 29 日 02:01 UTC +5 开始,然后移动到一个线程.

编辑 4

设置PYENV_DEBUG=1后,这里输出

(vmds) saadali@A006-00276 ~ :~$ pyenv+ [:22] enable -f/../libexec/pyenv-realpath.dylib realpath+ [:29] [ -z '' ']'+ [:31] READLINK=+ [:31] 输入 -p greadlink readlink+ [:31] READLINK=+ [:31] 头 -1+ [:31] READLINK='找不到 greadlink'+ [:32] [ -n 'greadlink 未找到' ']'+ [:57] [ -z '' ']'+ [:58] PYENV_ROOT=/Users/abc/.pyenv+ [:62] 导出 PYENV_ROOT+ [:65] [ -z '' ']'+ [:66] [ -n '' ']'+ [:82] [ -z '' ']'+ [:83] PYENV_DIR=/用户/abc+ [:86] [ !-d/Users/abc ']'+ [:86] [ !-e/Users/abc ']'+ [:90] PYENV_DIR=+ [:90] cd/Users/abc+ [:90] 回声/Users/abc+ [:90] PYENV_DIR=/Users/abc+ [:91] 导出 PYENV_DIR+ [:94] shopt -s nullglob/usr/local/bin/pyenv:94:找不到命令:shopt

解决方案

根据您的信息和评论,您的问题似乎有 3 个原因:

  1. pyenv 是一个 bash(和 bash-only)脚本,带有一个 shebang 行 #!/usr/bin/envbash
  2. /usr/local/bin 在你的 PATH 中出现在 /usr/bin/bin 之前,所以其中的可执行文件首先被选中通过 /usr/bin/env(期望的行为,尤其是在使用 homebrew 时)
  3. /usr/local/bin/bash 符号链接到 /bin/zsh!?!

所以最后你用 zsh 运行 pyenv,虽然它是 bash 的替代品,但不知道shopt,因此窒息.我不知道为什么符号链接到位,但它不应该,因为 zsh 不是 bash 的完全兼容的替代品.

我建议

  1. (如果您使用的是自制软件)
    检查您是否通过 homebrew 安装了 bash(后来不知何故被 zsh 的符号链接替换):

    # 只显示顶级包(直接安装)冲泡叶子# 显示带有依赖树的*所有*包brew deps --tree --installed

    如果不再需要,则卸载 bash(应该然后删除 /usr/local/bin/bash).

  2. 删除或至少重命名罪魁祸首:

    mv/usr/local/bin/bash/usr/local/bin/bash_link_to_zsh

    或者,如果某些程序需要 /usr/local/bin/bash 到位,只需让它指向 /bin/bash.

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

解决方案

According to your info and comments it seems your issue has 3 causes working hand in hand:

  1. pyenv is a bash (and bash-only) script with a shebang line #!/usr/bin/env bash
  2. /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)
  3. /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

  1. (in case you are using homebrew)
    Check if you have/had bash 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).

  2. 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.

这篇关于pyenv 在 macos 上给出 shopt 命令未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆