aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

ImportError when running the latest awscli with Python 1.7.15rc1

Open talonx opened this issue 8 years ago • 24 comments

talonx>% sudo -H pip install awscli   
Collecting awscli
  Using cached https://files.pythonhosted.org/packages/87/59/895121a6278c21e77b2aeddc23bf54b10486f0e641553672b765043834db/awscli-1.16.7-py2.py3-none-any.whl
Requirement already satisfied: docutils>=0.10 in /usr/local/lib/python2.7/dist-packages (from awscli) (0.13.1)
Collecting botocore==1.11.7 (from awscli)
  Using cached https://files.pythonhosted.org/packages/55/fd/99b9962da5e4ed41754aa23a6e030e4b2b844120edcb52a83124dc0af087/botocore-1.11.7-py2.py3-none-any.whl
Requirement already satisfied: PyYAML<=3.13,>=3.10 in /usr/lib/python2.7/dist-packages (from awscli) (3.12)
Requirement already satisfied: rsa<=3.5.0,>=3.1.2 in /usr/local/lib/python2.7/dist-packages (from awscli) (3.4.2)
Requirement already satisfied: colorama<=0.3.9,>=0.2.5 in /usr/lib/python2.7/dist-packages (from awscli) (0.3.7)
Requirement already satisfied: s3transfer<0.2.0,>=0.1.12 in /usr/local/lib/python2.7/dist-packages (from awscli) (0.1.13)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /usr/local/lib/python2.7/dist-packages (from botocore==1.11.7->awscli) (0.9.3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1; python_version >= "2.7" in /usr/local/lib/python2.7/dist-packages (from botocore==1.11.7->awscli) (2.6.1)
Requirement already satisfied: urllib3<1.24,>=1.20 in /usr/local/lib/python2.7/dist-packages (from botocore==1.11.7->awscli) (1.22)
Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python2.7/dist-packages (from rsa<=3.5.0,>=3.1.2->awscli) (0.4.4)
Requirement already satisfied: futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" in /usr/local/lib/python2.7/dist-packages (from s3transfer<0.2.0,>=0.1.12->awscli) (3.2.0)
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.11.7->awscli) (1.11.0)
Installing collected packages: botocore, awscli
Successfully installed awscli-1.16.7 botocore-1.11.7
talonx>% aws
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 19, in <module>
    from botocore.hooks import AliasedEventEmitter
ImportError: cannot import name AliasedEventEmitter

Python 2.7.15rc1 on Ubuntu 18.04.1 LTS

talonx avatar Sep 05 '18 08:09 talonx

Same problem on Amazon Linux 2018.03

Packages were updated today (from /var/log/yum.log): Sep 07 02:00:09 Updated: python27-botocore-1.10.82-1.67.amzn1.noarch Sep 07 02:00:11 Updated: aws-cli-1.15.83-1.49.amzn1.noarch

$ aws --version Traceback (most recent call last): File "/usr/bin/aws", line 19, in import awscli.clidriver File "/usr/lib/python2.7/dist-packages/awscli/clidriver.py", line 19, in from botocore.hooks import AliasedEventEmitter ImportError: cannot import name AliasedEventEmitter

It was fixed by downgrading aws-cli and python27-botocore: python27-botocore-1.8.13-1.66.amzn1.noarch.rpm aws-cli-1.14.9-1.48.amzn1.noarch.rpm

After downgrade: $ aws --version aws-cli/1.14.9 Python/2.7.14 Linux/4.9.85-37.55.amzn1.x86_64 botocore/1.10.49

jdkindy avatar Sep 07 '18 15:09 jdkindy

same problem here, fixed with a downgrade: $ aws --version aws-cli/1.14.70 Python/2.7.14 Linux/4.14.51-60.38.amzn1.x86_64 botocore/1.10.60

niklongstone avatar Sep 11 '18 15:09 niklongstone

 File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 19, in <module>
    from botocore.hooks import AliasedEventEmitter
ImportError: cannot import name AliasedEventEmitter

Apparently it seems to caused that the implementation of botocore has changed

https://github.com/boto/botocore/commit/f8b98a04437e3a314376bce702c2e8ad8320307f#diff-155031df2de133bd9d662433e654c09a

masahitojp avatar Sep 12 '18 05:09 masahitojp

https://github.com/aws/aws-cli/commits/develop/awscli/clidriver.py

Well, I already seem to be getting well with this latest version 🤔

masahitojp avatar Sep 12 '18 05:09 masahitojp

We had a similar problem after doing a yum update of aws-cli and python27-botocore. It turned out we also had a pip-installed botocore that was older than the version required by the new aws-cli. Removing (or else updating) the pip version resolved the issue. This might not be the same issue as @talonx reports but perhaps may help others who commented or are reading this thread.

chadawagner avatar Sep 12 '18 19:09 chadawagner

Same problem here an running a yum update on the Amazon AMI. Also fixed by downgrading aws-cli.noarch and python27-botocore:

sudo yum downgrade aws-cli.noarch python27-botocore

jphegley avatar Sep 12 '18 19:09 jphegley

@talonx It looks like for some reason the versions installed aren't actually being used.

Your output shows pip installing version 1.11.7 of botocore, which had the AliasedEventEmitter: https://github.com/boto/botocore/blob/1.11.7/botocore/hooks.py#L346, so this should work. My guess would be that the botocore that's being imported in the CLI isn't actually v1.11.7.

You could try this to see if the versions match up:

$ python -c "import botocore; print('%s: %s' % (botocore.__file__, botocore.__version__))"

We've also made a few changes since v1.16.7. Are you still seeing this issue on the latest version?

jamesls avatar Sep 12 '18 20:09 jamesls

@jdkindy It looks like the same issue in my previous comment, for whatever reason, even though you've installed 1.10.82, that's not the version that's actually being used in the CLI. v1.10.82 of botocore also has the AliasedEventEmitter as shown here so that should work without issue: https://github.com/boto/botocore/blob/1.10.82/botocore/hooks.py#L346

I also confirmed that if I install the CLI in a new virtualenv I'm not seeing any issues with either version affected here:

$ pip install awscli==1.15.83
Collecting awscli==1.15.83
  Downloading https://files.pythonhosted.org/packages/59/d6/94d35bb4a0b90decb9829b0c6ef9d73306ec52993c790d3dfd4be83cd9e3/awscli-1.15.83-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 6.7MB/s
Collecting PyYAML<=3.13,>=3.10 (from awscli==1.15.83)
Collecting docutils>=0.10 (from awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/50/09/c53398e0005b11f7ffb27b7aa720c617aba53be4fb4f4f3f06b9b5c60f28/docutils-0.14-py2-none-any.whl
Collecting botocore==1.10.82 (from awscli==1.15.83)
  Downloading https://files.pythonhosted.org/packages/03/29/89e029b98e4abdc81d3cdffe27aab7eb7e5bfea32d8d2e08227c5b89904b/botocore-1.10.82-py2.py3-none-any.whl (4.5MB)
    100% |████████████████████████████████| 4.5MB 3.8MB/s
Collecting rsa<=3.5.0,>=3.1.2 (from awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl
Collecting colorama<=0.3.9,>=0.2.5 (from awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/db/c8/7dcf9dbcb22429512708fe3a547f8b6101c0d02137acbd892505aee57adf/colorama-0.3.9-py2.py3-none-any.whl
Collecting s3transfer<0.2.0,>=0.1.12 (from awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/d7/14/2a0004d487464d120c9fb85313a75cd3d71a7506955be458eebfe19a6b1d/s3transfer-0.1.13-py2.py3-none-any.whl
Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.10.82->awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/b7/31/05c8d001f7f87f0f07289a5fc0fc3832e9a57f2dbd4d3b0fee70e0d51365/jmespath-0.9.3-py2.py3-none-any.whl
Collecting python-dateutil<3.0.0,>=2.1; python_version >= "2.7" (from botocore==1.10.82->awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl
Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/d1/a1/7790cc85db38daa874f6a2e6308131b9953feb1367f2ae2d1123bb93a9f5/pyasn1-0.4.4-py2.py3-none-any.whl
Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer<0.2.0,>=0.1.12->awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.10.82->awscli==1.15.83)
  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: PyYAML, docutils, jmespath, six, python-dateutil, botocore, pyasn1, rsa, colorama, futures, s3transfer, awscli
Successfully installed PyYAML-3.13 awscli-1.15.83 botocore-1.10.82 colorama-0.3.9 docutils-0.14 futures-3.2.0 jmespath-0.9.3 pyasn1-0.4.4 python-dateutil-2.7.3 rsa-3.4.2 s3transfer-0.1.13 six-1.11.0
(tmp-ce22f5caa8723ec7) ~/.virtualenvs/tmp-ce22f5caa8723ec7 $ aws --version
aws-cli/1.15.83 Python/2.7.14 Darwin/16.7.0 botocore/1.10.82

jamesls avatar Sep 12 '18 20:09 jamesls

@jamesls test a fresh instance with the Amazon Linux AMI 2018.03.0.20180811 x86_64 HVM AMI and running yum update -y.

texdc avatar Sep 13 '18 15:09 texdc

@jamesls you stated: "Your output shows pip installing version 1.11.7 of botocore, which had the AliasedEventEmitter: https://github.com/boto/botocore/blob/1.11.7/botocore/hooks.py#L346, so this should work. My guess... "

but, this commit(changing name of class 'AliasedEventEmitter' to 'EventAliaser'): https://github.com/boto/botocore/commit/f8b98a04437e3a314376bce702c2e8ad8320307f#diff-155031df2de133bd9d662433e654c09a was a child of this commit: https://github.com/boto/botocore/commit/384523c1d3dadacbab9edb81750c76f1f0559cad which was in the 1.11.7 release (unless I am reading things incorrectly)

It seems (as previously mentioned by @masahitojp) that the root cause appears to be coming from botocore.

johnbartels avatar Sep 13 '18 18:09 johnbartels

The update of the botocore installed with pip works to me to solve this issue:

pip install botocore==1.10.82

netmanuy avatar Sep 13 '18 20:09 netmanuy

Running pip install awscli==1.15.83 fixed it for me. The way to validate was to run aws --version before and after the pip install.

gitbisect avatar Sep 14 '18 06:09 gitbisect

It seems to me that actually this is all that is needed: pip install awscli Takes care of botocore too

smet-dk avatar Sep 14 '18 11:09 smet-dk

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

no-response[bot] avatar Sep 19 '18 22:09 no-response[bot]

It seems to me that actually this is all that is needed: pip install awscli Takes care of botocore too

https://github.com/aws/aws-cli/issues/3542#issuecomment-421328359

So this works, but you have to remove aws-cli via yum first completely. Then when installing the awscli via pip the exact command should be: pip install awscli --ugprade --user After that you have to update the path of the account you're in, and it works.

The only issue then you run into is that the upgrade/update only affects the account in question where its run first. So if you need it to be done globally, you need to look into modifying /etc/profile or profile.d or the ~/.bashrc files of each accounts on the instance in question.

That said, doing all of the above still leads to breakages if you have shell scripts that are leveraged by specific apps like tomcat:

sudo service tomcat restart /opt/tomcat/bin/setenv.sh: line 4: aws: command not found /opt/tomcat/bin/setenv.sh: line 5: aws: command not found /opt/tomcat/bin/setenv.sh: line 6: aws: command not found /opt/tomcat/bin/setenv.sh: line 7: aws: command not found /opt/tomcat/bin/setenv.sh: line 8: aws: command not found /opt/tomcat/bin/setenv.sh: line 12: aws: command not found /opt/tomcat/bin/setenv.sh: line 13: aws: command not found Using CATALINA_BASE: /opt/tomcat

and sudo is involved. I have not yet found a way to address this yet.

[Edit]

Easiest path forward would be to grab the latest CLI release and use the explicit boto version stated by looking at the commit ID and installing that (plus uninstalling any previous versions you might get with any other boto packages you might have grabbed in the process). That worked for me.

AnishBAH avatar Oct 09 '18 18:10 AnishBAH

pip install awscli --upgrade worked for me.

I saw a post saying boto requires higher version of awscli so that the error occurs. Upgrade the awscli first and then try it!

burning-croissant avatar Oct 11 '18 03:10 burning-croissant

pip install awscli==1.15.83 fixed it for me...

1001b avatar Oct 15 '18 18:10 1001b

smet-dk solution worked for me sudo pip install awscli

tauqirghani avatar Feb 14 '19 22:02 tauqirghani

smet-dk solution worked for me sudo pip install awscli

Yes, this worked for me too.

CloudSatish avatar Feb 17 '19 00:02 CloudSatish

I had similar issue. It looks like aws cli copy command is working on emr-5.17.0 but not emr-5.20.0. Downgrade the aws-cli.noarch and python27-botocore by running: "$ sudo yum downgrade aws-cli.noarch python27-botocore" did fix the problem. But after some more testing, I found out emr-5.17.0 or emr-5.20.0 is not the problem. aws cli copy command works on both EMR versions. The problem is in my bootstrap script. I ran "$ sudo pip install boto3", this installation uninstalled botocore-1.10.82 and installed boto3-1.9.109 botocore-1.12.109. That's why running "$ sudo pip install awscli" also fix the problem. Because it uninstalled botocore-1.12.105 and installed botocore-1.10.82 for you.

amyjiwu avatar Mar 08 '19 00:03 amyjiwu