如何解决“ dyld: 库未加载:@Executive_path. .”错误

我试图在我的 MAC OS X 上检查 AWS-CLI 版本:

dyld: Library not loaded: @executable_path/../.Python
Referenced from: /usr/local/aws/bin/python
Reason: image not found
Abort trap: 6

如能就如何解决这一问题提供相关的意见,我们将不胜感激。

76100 次浏览

发生此错误是因为虚拟环境中断了符号链接。 下面是来自 Tevino 的 fix_virtualenv要点的一个不错的解决方案:

#!/usr/bin/env bash


ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"


BAD_ENV_PATHS="/usr/local"


echo "Ensure the root of the broken virtualenv:"
echo "    $ENV_PATH"


if [[ -z "$ENV_PATH" ]] || [[ "$ENV_PATH" = *"$BAD_ENV_PATHS"* ]]; then
echo "The root path above doesn't seems to be a valid one."
echo "Please make sure you ACTIVATED the broken virtualenv."
echo "‼️  Exiting for your safety... (thanks @laymonk for reporting this)"
exit 1
fi


read -p "‼️  Press Enter if you are not sure (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "♻️  Removing old symbolic links......"
find "$ENV_PATH" -type l -delete -print
echo "💫  Creating new symbolic links......"
$SYSTEM_VIRTUALENV "$ENV_PATH"
echo "🎉  Done!"
fi

此外,还有一个类似的问题: Broken references in Virtualenvs.

我在 Mac 上安装自制的 awscli 时也遇到过类似的问题。 所以最后一种方法是“酿造卸载 python3”并重新安装 awscli。

您一定是搞错了酿造。尝试使用: brew install awscli重新安装它(如果需要,后面跟着 brew link awscli)。

It is a bug with awscli and it might be fixed with the next versions. That's why, a best practices is to upgrade :

brew upgrade awscli

如果你已经有了 python (巨蟒,版本工作。如果没有安装它与 酿造安装 Python)。 这对我很有用:

  1. 卸载 aws

    $ sudo rm -rf /usr/local/aws
    $ sudo rm /usr/local/bin/aws
    
  2. Install it again

    $ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
    $ unzip awscli-bundle.zip
    $ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
    

我用卷发装的,正常的方式

$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

然后它停止工作,抱怨找不到 python2.7

dyld: Library not loaded: @executable_path/../.Python
Referenced from: /usr/local/aws/bin/python2.7
Reason: image not found
Abort trap: 6

因此,我通过以下步骤修复了它(如果你是通过 brew安装的,请确保不要这样做) :

$ sudo rm -rf /usr/local/aws
$ sudo rm /usr/local/bin/aws

然后我用“啤酒”安装了它:

$ brew upgrade
$ brew install awscli

通过在虚拟列表中出现问题来触发这个错误是可能的。例如,我有一个现有的工作虚拟机并运行 brew install awscli,它用这个错误破坏了我的虚拟机。如果是这种情况,那么删除并重新创建 Virtual alenv (与您最初创建它的方法相同)应该可以解决这个问题。对我来说是的。

读过这个话题后,我觉得很有用:

  1. 卸载 aws
$ sudo rm -rf /usr/local/aws
$ sudo rm /usr/local/bin/aws
  1. 再装一次
    $ brew reinstall awscli

这对我有用。

brew upgrade
brew uninstall aws-sam-cli
brew install aws-sam-cli

如果:

  • 你重新安装/重新连接了 awscli
  • 并且在您使用 蟒蛇诗虚拟环境时遇到这个问题

然后删除环境,比如:

# MacOS paths
rm -rf /Users/<user>/Library/Caches/pypoetry/virtualenvs/<your_virtual_env_name>

要获得 env 的名称和路径,你可以这样做:

poetry shell

会出现类似的错误:

 EnvCommandError


Command ['/Users/<user>/Library/Caches/pypoetry/virtualenvs/<your_virtual_env_name>/bin/python', '-W', 'ignore', '-'] ...

复制 env 路径,执行 rm -rf <path>,然后执行 poetry shell

如果您按照 AWS 在 https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html上的官方说明通过 curl 安装了 AWS CLI,那么只需重新运行这些命令,而不需要事先删除,就可以解决这个问题:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg ./AWSCLIV2.pkg -target /

我尝试了以上所有的解决方案,但都没有效果 then I tried this from https://docs.aws.amazon.com/cli/v1/userguide/install-macos.html and it worked :
sudo /usr/local/bin/python3.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws