ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc' in AWS CodeBuild
Asked Answered
A

10

83

ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc'
(/python3.7/site-packages/botocore/docs/bcdoc/init.py)

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.7.6/bin/aws", line 19, in <module>
    import awscli.clidriver

  File "/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/awscli/clidriver.py", line 36, in <module>
    from awscli.help import ProviderHelpCommand

  File "/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/awscli/help.py", line 23, in <module>
    from botocore.docs.bcdoc import docevents

ImportError: cannot import name 'docevents' from 'botocore.docs.bcdoc' (/root/.pyenv/versions/3.7.6/lib/python3.7/site-packages/botocore/docs/bcdoc/__init__.py)

[Container] 2020/10/29 16:48:39 Command did not exit successfully aws --version exit status 1

The failure occurs in the PRE_BUILD.

And this is my spec build file: buildspec-cd.yml

pre_build:
    commands:
      - AWS_REGION=${AWS_DEFAULT_REGION}
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_VERSION=${COMMIT_HASH}
      - REPOSITORY_URI=${CONTAINER_REGISTRY}/${APPLICATION_NAME}
      - aws --version
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)

The codebuild was working correctly and nothing has been changed. Only stopped working.

Almsman answered 29/10, 2020 at 17:34 Comment(0)
A
176

Reading this GitHub issue #2596. i fixed my error.

Just before the PRE_BUILD section, I added this line to my buildspec-cd.yml file:

pip3 install --upgrade awscli

install:
    commands:
      - pip3 install awsebcli --upgrade
      - eb --version
      - pip3 install --upgrade awscli

    pre_build:
      commands:
      - AWS_REGION=${AWS_DEFAULT_REGION}
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_VERSION=${COMMIT_HASH}
      ...
Almsman answered 29/10, 2020 at 23:9 Comment(1)
in my case i also had to pip3 install --upgrade pip before upgrading awscliBrezin
P
14

For me it's a version issue. So, I fixed it with below versions:

  1. aws-cli/1.18.105

Command: sudo python3 -m pip3 install awscli==1.18.105

  1. botocore/1.17.28

Command: sudo python3 -m pip3 install botocore==1.17.28

Pericranium answered 4/2, 2021 at 5:13 Comment(1)
whomsoever it may concern: Please use any of pip or pip3 << whatever you have configured in your systemPericranium
M
9

In my case this error occurs running the command 'aws --version' on ubuntu 20.04.

And the solution was:

python3 -m pip install --upgrade pip
python3 -m pip uninstall awscli
python3 -m pip install awscli
Mandimandible answered 5/3, 2022 at 18:9 Comment(1)
Tried this on Ubuntu 20.04, which runs Python 3.8. It didn't work - got the same error. boto3 version is 1.24.45, botocore version is 1.27.45, and awscli version is 1.18.69Bulldog
A
6

Upgrade pip (not necessary but it's better to do otherwise it will throw a Warning message while running the second command.)

python3 -m pip install --upgrade pip

Upgrade awscli (Necessary)

pip3 install --upgrade awscli

Add sudo in both commands if required to have root user permissions.

Assumed answered 28/11, 2022 at 8:34 Comment(0)
A
4

Was getting the same error on Ubuntu 20.04, the answer from @vijay rajput did not work at the beginning, fixed by replacing pip3 with pip - sudo python3 -m pip install awscli==1.18.105 and sudo python3 -m pip install botocore==1.17.28 Thx

Agonic answered 13/6, 2021 at 13:28 Comment(3)
Just a note - confirmed that this does work on Ubuntu 20.04, unlike some other answers.Bulldog
This also worked for me on 20.04Friseur
this worked for 20.04Zumstein
M
0

pip uninstall botocore worked for me

Millwork answered 31/1, 2022 at 0:42 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Bordiuk
Agreed. botocore is a core library within awscli, so this really needs supporting information.Pigeon
C
0

I also got this error on Ubuntu 20.04 (though not in CodeBuild, I was running aws lambda invoke). Installing the AWS CLI v2 (https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html) worked for me:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Cabana answered 11/2, 2022 at 20:56 Comment(2)
Tried this on Ubuntu 20.04 - still got the same error. Versions: boto3 1.24.45; botocore 1.27.45; awscli: 1.18.69. What versions do you have?Bulldog
@Craig S. Anderson aws-cli 2.5.3, boto3 1.21.36, botocore 1.24.36Cabana
C
0

For anyone who stumbles upon this question, in Ubuntu 20.04, if you install the awscli using apt (apt install awscli), the version it will install is 1.18.69, which is not compatible with later botocore versions. To fix the issue, either install the awscli through pip instead of through apt (so you can install the latest, which does work as of December 2022 with 1.27.30), or downgrade the botocore version. The last botocore which will work correctly with awscli version 1.18.69 is 1.17.63, which has a corresponding boto3 release of 1.14.63.

Clavicytherium answered 15/12, 2022 at 19:57 Comment(0)
B
0

I did a fresh install of Ubuntu 20.04, then installed awscli and boto3 using pip3. I then looked at the versions installed. From that I created the following, which seemed to fix the problems on existing machines:

sudo pip3 install awscli==1.27.140 boto3==1.26.140 botocore==1.29.140 s3transfer==0.6.1
Bulldog answered 25/5, 2023 at 17:34 Comment(0)
E
0
pip3 install awsebcli --upgrade
pip3 install --upgrade awscli

If you still see error like:

 File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

Then run

pip install pip --upgrade
pip install pyopenssl --upgrade

as mentioned here: AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

Expendable answered 16/6, 2023 at 22:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.