awscli fails to work: No module named 'awscli'

Python 3.xPipAws Cli

Python 3.x Problem Overview


I am trying to install awscli using pip3 on Linux Mint 17.2 Rafaela.

I am getting the error:

Traceback (most recent call last):
  File "/home/jonathan/.local/bin/aws", line 19, in <module>
    import awscli.clidriver
ImportError: No module named 'awscli'

These are the steps I am taking, following the aws installation guide:

sudo pip install awscli --upgrade --user

everything seems to install fine.

adding to my .bashrc

export PATH=~/.local/bin:$PATH

then

source ~/.bashrc

then i try the command

aws --version

and i get

Traceback (most recent call last):
  File "/home/jonathan/.local/bin/aws", line 19, in <module>
    import awscli.clidriver
ImportError: No module named 'awscli'

Can anyone help with this?

EDIT: For anyone visiting this question. There is no way I can test any of these answers because I have since removed this OS and installed Ubuntu. Also I have no need for awscli anymore.

Python 3.x Solutions


Solution 1 - Python 3.x

I had the same issue. I realized that awscli wasn't installed in /usr/local/lib/python3.5 but instead in /.local/usr . So i uninstalled awscli using

sudo pip3 uninstall awscli

and just used this

sudo pip3 install awscli

that solved the issue for me. Now aws --version is working perfectly. Also make sure you remove all the dependencies of awscli which were installed in the /.local folder, you can simply uninstall all of them, and then run the above command.

Solution 2 - Python 3.x

On Windows 10 64bit I was getting the same error.

I have Python 2.7 and 3.7 installed on my PC. I tried the installing awscli using both of the following commands:

pip install --upgrade --user awscli
pip install awscli

I uninstalled the awscli using pip after using the first command.

After running the second command the error message persisted.

I solved the problem by changing the order of paths to search in my "System" PATH variable.

My "System" PATH variable looked like this:

C:\Program Files\Python\Python27\ 
C:\Program Files\Python\Python27\Scripts
C:\Program Files\Python\Python37\
C:\Program Files\Python\Python37\Scripts

So I used the "Move Up/ Down" buttons in the Environment Variables Control Panel to change the order to look like this:

C:\Program Files\Python\Python37\
C:\Program Files\Python\Python37\Scripts
C:\Program Files\Python\Python27\
C:\Program Files\Python\Python27\Scripts

Now the awscli is running without issues.

Solution 3 - Python 3.x

This happens because of many reasons, one of it is wrong installation of aws

> sudo pip install aws

Proper way of installing is (this should work if u do it without messing it up): > sudo pip install --upgrade --user awscli

Otherwise if you get any errors like: import awscli.clidriver

Then execute the command below to fix it:

sudo pip install awscli --force-reinstall --upgrade

and your awscli will be installed in (for Ubuntu 16)

> /usr/local/bin/aws

Set the aws path:

export PATH=~/.local/bin:$PATH

Solution 4 - Python 3.x

I had this problem, Fixed it with below command.

$sudo pip install awscli --force-reinstall --upgrade && sudo chmod 755 /bin/aws

Solution 5 - Python 3.x

In my case, I must have ran a pip command with sudo that I shouldn't have, causing root to be the owner of various subdirectories of ~/.local/ which should be owned by me. Running sudo -H aws --version would work, but aws --version would not.

Running this to correct the owner fixed a lot of my problems:

sudo chown -R $USER ~/.local

Solution 6 - Python 3.x

I created the same situation by first did pip install awscli, then did sudo pip install awscli. After running

sudo pip uninstall awscli 
sudo pip install awscli

I still got problems. I have to manually remove the $HOME/.local directory with sudo rm -rf .local

Solution 7 - Python 3.x

I had a similar problem but under Windows 10

I used pip3 install awscli --upgrade --user like it is recommended by Amazon.

So in my case the problem was that I had 27 and 36 pythons installed:

D:\ff>where python.exe
C:\Users\me\.windows-build-tools\python27\python.exe
C:\Users\me\AppData\Local\Programs\Python\Python36\python.EXE

And I need them both...

> Note here that you can just swap the order of entries in the PATH global variable like @WStrellis suggested: https://stackoverflow.com/a/55071644/139667 or you can use this trick...

... so what I did is:

In the folder where I needed aws I created

  1. file aws.bat

    C:\Users\me\AppData\Local\Programs\Python\Python36\python.EXE aws.py %*
    
  2. file aws.py

    import awscli.clidriver
    import sys
    
    
    def main():
        return awscli.clidriver.main()
    
    
    if __name__ == '__main__':
        sys.exit(main())
    

now I can run the aws console from that folder just like it's real:

aws help

The advantages of doing this is that:

  • This configuration is easily transferable (by pushing it with the rest of the files to git for example), so whoever else needs it can take advantage of it without going through the same troubles (provided they have Python 3.x and ran pip3 install awscli --upgrade --user).
  • This configuration is local (to the folder), in a different folder you can use something else and it's not going to have anything in common with this one.

Solution 8 - Python 3.x

I had the same issue.
Just wrote:

pip3 install --upgrade awscli

and my issue was solved.

Solution 9 - Python 3.x

I tried installing hard with many ways. Following what worked for me. Uninstall aws-cli using pip. it can be pip3 or just pip. Ensure not to use sudo while installing back. Do following:

  • Uninstall already installed one using

> sudo pip uninstall awscli

  • Install back using without sudo and this time it should work.

> pip install awscli

Now check aws-cli installation successful or not using below > aws --version

Shows below result if works well. In my case it shows as: > aws-cli/1.16.60 Python/2.7.15+ Linux/4.18.0-11-generic botocore/1.12.50

Solution 10 - Python 3.x

Thanks for this help.

https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html#awscli-install-osx-path

I followed the instructions, after going through all those steps got an error:

$aws
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 19, in <module>
    import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'

This post help to fix it , also need to fix this

WARNING: The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/Users/xxx/Library/Python/3.7/bin' which is not on PATH.

and run

pip3 install awscli --force-reinstall --upgrade --user

Solution 11 - Python 3.x

First off, uninstall whatever you just tried with sudo pip uninstall awscli. If you had installed with the --user flag, make sure to remove any aws remnants in ~/.local/ with:

sudo rm -f ~/.local/bin/aws*

If you had followed directions from aws docs to modify your $PATH, and ~/.bashrc, undo by deleting the line you added to ~/.bashrc and run:

exec -l $SHELL

For Ubuntu 18.04, here's what worked for me:

Recommended install command from AWS docs:

sudo pip install --upgrade --user awscli

I found that after doing this, the aws binary was missing from path, and somehow adding it to $PATH as they recommended didn't work.

Execute the command below to fix this:

sudo pip install awscli --force-reinstall --upgrade

Solution 12 - Python 3.x

I figured the root cause for this. Mojave put some chains around disk access. http://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/

Then use

sudo -H pip3 uninstall awscli
sudo -H pip3 install awscli

Solution 13 - Python 3.x

Not a very robust solution, but similarly to the answer above, it's good to check your Python version. I had installed awscli to Python 3.5 (my default Python), via pip (pip install awscli) and was able to import it from a Python 3.5 REPL, but when I ran the aws executable command on the command line, I still received the same error as above. I opted to manually change the Python version of the aws executable file from 2.7 to 3.5

  1. chmod 777 /usr/bin/aws # Grants edit access to the aws executable
  2. vi /usr/bin/aws # Opens executable in editor
  3. Changed the following in #!usr/bin/python2.7: python2.7 --> python3.5

If you need to re-adjust the file permissions for security purposes after, I would recommend doing that as well.

Hope this helps! For reference, I'm using CentOS 7 as my operating system.

Solution 14 - Python 3.x

If you are using pipx and you run into this, I tried uninstalling and re-installing e.g. pipx uninstall awscli; pipx install awscli - that still didn't work.

I wound up reinstalling everything in pipx pipx reinstall-all which finally worked - not sure why though - shared library updates?

pipx is awesome but still a little magical since I've not dived into the internals yet.

Solution 15 - Python 3.x

I got into the same problem @ec2 ubuntu instance. What helped was to upgrade pip version: you get initially pip v 9.0.1. Upgrade it to current version (18.0 on day of writing this ) and you'll be fine

pip install --upgrade pip

Solution 16 - Python 3.x

I got this command trying to run the AWS CLI, that I had already installed months ago so reinstalling it seemed like the wrong thing to do for me.

I tried to install it again but got a message saying this action was already completed.

I was to able to resolve this error by setting the 'path variable' using this code from where Python is installed on my machine. This code below has helped me a lot in my coding tasks.

setx PATH “C:\Users\user\AppData\Local\Programs\Python\Python35-32

Now I am able to run aws configure which is what I wanted to do anyway. Check out: Install the AWS CLI on Windows for more guidance in this matter.

Solution 17 - Python 3.x

I had this problem. On first attempt at installation I had not used the --upgrade option. When I retried the install with --upgrade it worked. Also you don't need to use sudo if you are using --user.

Solution 18 - Python 3.x

Path order does matter if you have multiple version of Python installed specially ANACONDA. Prioritize your newly installed script directory path among all anaconda.

Solution 19 - Python 3.x

In my case, I had to install boto

sudo pip3 install boto


sudo pip3 install boto3

https://searchaws.techtarget.com/definition/Boto

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThriceGoodView Question on Stackoverflow
Solution 1 - Python 3.xRonald DasView Answer on Stackoverflow
Solution 2 - Python 3.xWStrellisView Answer on Stackoverflow
Solution 3 - Python 3.xRavistmView Answer on Stackoverflow
Solution 4 - Python 3.xJay ReddyView Answer on Stackoverflow
Solution 5 - Python 3.xuser3300900View Answer on Stackoverflow
Solution 6 - Python 3.xKemin ZhouView Answer on Stackoverflow
Solution 7 - Python 3.xTrident D'GaoView Answer on Stackoverflow
Solution 8 - Python 3.xJuverView Answer on Stackoverflow
Solution 9 - Python 3.xMukesh Singh RathaurView Answer on Stackoverflow
Solution 10 - Python 3.xChandanView Answer on Stackoverflow
Solution 11 - Python 3.xWillView Answer on Stackoverflow
Solution 12 - Python 3.xCodistanView Answer on Stackoverflow
Solution 13 - Python 3.xRyan SanderView Answer on Stackoverflow
Solution 14 - Python 3.xWilliamView Answer on Stackoverflow
Solution 15 - Python 3.xlsa77View Answer on Stackoverflow
Solution 16 - Python 3.xShegs84View Answer on Stackoverflow
Solution 17 - Python 3.xTony JoblinView Answer on Stackoverflow
Solution 18 - Python 3.xRupesh JhaView Answer on Stackoverflow
Solution 19 - Python 3.xTshegofatso LegwaleView Answer on Stackoverflow