56

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.

ThriceGood
  • 1,383
  • 3
  • 16
  • 38

18 Answers18

60

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.

Ronald Das
  • 795
  • 8
  • 13
  • thank you, i seemed to have got passed the initial problem, but now im having another issue, `No module named 'dateutil'`. I'm wondering if its my python3 version thats out of date for awscli, i have 3.4.3 – ThriceGood Jun 06 '17 at 09:10
  • If you followed the instructions in https://docs.aws.amazon.com/cli/latest/userguide/installing.html they recomend to install python for your user only `pip install awscli --upgrade --user` to avoid conflicts with previous versions. I had this issue too. – German Feb 14 '18 at 12:51
14

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.

WStrellis
  • 141
  • 1
  • 3
  • Thanks. This one helped me out. Although I had `awscli` installed in Python27 so needed to switch them from the second state to the first. Time to upgrade I think. – PhilT May 12 '20 at 14:09
11

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
Shafique Jamal
  • 1,386
  • 3
  • 17
  • 38
Ravistm
  • 1,779
  • 22
  • 23
7

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

Kemin Zhou
  • 4,375
  • 1
  • 29
  • 47
7

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
user3300900
  • 71
  • 1
  • 1
7

I had this problem, Fixed it with below command.

$sudo pip install awscli --force-reinstall --upgrade && sudo chmod 755 /bin/aws
Jay Reddy
  • 196
  • 1
  • 2
  • 1
    i recently upgraded from ubuntu 19.10 to 20.04, and had to run just: `sudo pip3 install awscli --force-reinstall --upgrade` for it to work again – Martin Hansen Jul 27 '20 at 11:17
6

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.
Trident D'Gao
  • 15,993
  • 14
  • 77
  • 141
2

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

Mukesh Singh Rathaur
  • 11,323
  • 2
  • 21
  • 24
2

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
cccnrc
  • 1,154
  • 8
  • 21
Chandan
  • 31
  • 1
1

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
Will
  • 236
  • 6
  • 16
  • 1
    The last command did it for me `sudo apt install python-pip && sudo pip install awscli --force-reinstall --upgrade` – mbarkhau Mar 26 '19 at 11:24
1

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
Codistan
  • 859
  • 1
  • 8
  • 12
1

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.

Ryan Sander
  • 341
  • 2
  • 6
1

I had the same issue.
Just wrote:

pip3 install --upgrade awscli

and my issue was solved.

willcrack
  • 1,496
  • 7
  • 18
Juver
  • 11
  • 1
0

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
lsa77
  • 15
  • 1
  • 3
0

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.

Shegs84
  • 13
  • 1
0

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.

0

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.

William
  • 577
  • 4
  • 15
0

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