128

I was trying to check the AWS-CLI version on my MAC OS X. And the below error hit back:

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

Any relevant inputs on how to fix this would be highly appreciated.

Manogna Mujje
  • 1,291
  • 2
  • 7
  • 4
  • 13
    This error can occur when you `brew install some_package` when you are inside a virtualenv. I think what happens is brew does its work inside the vm. To fix it, deactivate from your virtualenv, `rm -rf` your virtual environment folder. Then rebuild it from scratch. Then put a loud comment that says don't brew install stuff inside a virtual environment. – Eric Leschinski Sep 25 '19 at 02:33
  • If you don't want to rebuild it from scratch follow this [link](https://xrubio.com/2016/05/fixing-python-virtualenv-on-os-x/) It worked for me – PAC Jan 21 '20 at 15:32

12 Answers12

100

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
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • 17
    if you have a broken symlink this will not work. it will tell you that awscli isn't installed and you'll end up having to run `brew link --overwrite awscli` and that's what worked for me. I upvoted because it was a start down the right path. – str8up7od Apr 12 '19 at 14:37
  • If you follow the instructions on the AWS CLI page this won't work https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html – jcollum Jan 06 '20 at 02:18
  • 2
    A similar note for those running into a similar issue with `eb`, you can run `brew upgrade aws-elasticbeanstalk`. – Sean Chon Mar 25 '20 at 21:53
  • 1
    I has no aswcli, for example – Atombit Jul 13 '20 at 11:02
  • i am getting this error and with no connected to aws-cli. i do run multiple virtualenv's on my laptop, and my python3 was recently upgraded from 3.7 to 3.9 – Rohit Chatterjee Dec 05 '20 at 06:35
36

You must have messed up with the brew. Try reinstalling it using: brew install awscli (followed by brew link awscli if needed).

Nabin
  • 11,216
  • 8
  • 63
  • 98
  • 1
    This didn't, also due to this error: `Error: awscli 1.14.60 is already installed` – axel Jan 30 '19 at 18:56
26

After read the topic, It works for me:

  1. Uninstall aws
$ sudo rm -rf /usr/local/aws
$ sudo rm /usr/local/bin/aws
  1. Reinstall it again
    $ brew reinstall awscli
Gleb Belyaev
  • 1,009
  • 1
  • 14
  • 23
18

This error occurs because your virtual environment has broken symlinks. Here is a nice solution taken from tevino's fix_virtualenv gist:

#!/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

Also, here is a similar question: Broken references in Virtualenvs.

kba
  • 19,333
  • 5
  • 62
  • 89
Andrii
  • 822
  • 10
  • 24
  • Amazing, this fixed my issue immediately – Our_Benefactors Sep 25 '19 at 21:02
  • How does one run this? – Ren Feb 20 '20 at 20:00
  • 3
    Summary of solution: 1) Delete all symlinks inside your virtual environment by running `find your-virtual-env-directory -type l -delete` 2) Recreate the symlinks inside your virtual environment by running `virtualenv your-virtual-env-directory` – alejandro Feb 29 '20 at 18:40
  • I am getting the error `OSError: Command /Users/defaultuser/D...o/venv/bin/python3.7 - setuptools pip wheel failed with error code -6` when I run the command `$SYSTEM_VIRTUALENV "$ENV_PATH"`. No idea what is error code "-6" – jerrymouse Jun 30 '20 at 07:50
  • Don't use it! It deleted all of my important symlinks in home dir. and did not created any new ones. Instead it gave an error line 24: .: filename argument required – Atombit Jul 13 '20 at 11:07
2

I had similar issue while installing awscli with homebrew on mac. So final approach was "brew uninstall python3" and reinstall awscli again.

Zaur
  • 431
  • 4
  • 5
2

If you have already python (python --version works. If not install it with brew install python). It works for me:

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

I had it installed through curl, the regular way

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

Then it stopped working complaining about not finding python2.7

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

so I fixed it by following these steps (make sure you don't do this if you installed it through brew):

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

Then I installed it using brew:

$ brew upgrade
$ brew install awscli
2

It's possible to trigger this error by having a problem in your virtualenv. For example, I had an existing working virtualenv and ran brew install awscli and it broke my virtualenv with this error. If that's the case, deleting and recreating your virtualenv (the same way you originally created it) should resolve the problem. It did for me.

Will
  • 6,601
  • 3
  • 31
  • 42
2

I tried all the above solutions and nothing worked 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

mathéo
  • 21
  • 1
0

This work for me.

brew upgrade
brew uninstall aws-sam-cli
brew install aws-sam-cli
msenatori
  • 1
  • 1
  • 1
0

If:

  • you reinstalled/relinked awscli
  • and are experiencing this issue while you work on a Python Poetry virtual env

Then just delete the env like:

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

To get the name and path of the env you can do:

poetry shell

There will be an error similar to this:

 EnvCommandError

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

Copy the env path, do rm -rf <path> and after that do poetry shell

Bartłomiej Skwira
  • 1,701
  • 1
  • 16
  • 24
0

If you installed AWS CLI via curl according to AWS' official instructions at https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html, simply rerunning these commands without any prior deletions solved it for me:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg ./AWSCLIV2.pkg -target /
André
  • 2,042
  • 1
  • 23
  • 26