ThriceGood
ThriceGood

Reputation: 1703

awscli fails to work: No module named 'awscli'

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.

Upvotes: 73

Views: 118247

Answers (21)

maxTrialfire
maxTrialfire

Reputation: 551

This can also happen (on Ubunu) if you have both python2 and python3 installed and python symbolic link points to your 3.x version. Simply change your symbolic link for python to point to python2.x instead of python3. Note: this will affect all other python apps that depend on version 3 but this was quick fix in my face.

Upvotes: 0

Matt Duguid
Matt Duguid

Reputation: 94

exact same error, i got this when trying to run the command 'aws' and the fix was to run command 'awsv2' as that is what we wanted to use anyway

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

/ # awsv2 --version
2.2.0

Upvotes: 0

Tshegofatso Legwale
Tshegofatso Legwale

Reputation: 9

In my case, I had to install boto

sudo pip3 install boto


sudo pip3 install boto3

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

Upvotes: 0

Ronald Das
Ronald Das

Reputation: 1277

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.

Upvotes: 83

Rupesh Jha
Rupesh Jha

Reputation: 1

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

Upvotes: 0

William
William

Reputation: 785

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.

Upvotes: 1

Juver
Juver

Reputation: 111

I had the same issue.
Just wrote:

pip3 install --upgrade awscli

and my issue was solved.

Upvotes: 11

Ryan S
Ryan S

Reputation: 479

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.

Upvotes: 1

Jay Reddy
Jay Reddy

Reputation: 700

I had this problem, Fixed it with below command.

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

Upvotes: 10

Chandan
Chandan

Reputation: 31

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

Upvotes: 2

Codistan
Codistan

Reputation: 1519

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

Upvotes: 1

Tony Joblin
Tony Joblin

Reputation: 1

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.

Upvotes: 0

Trident D&#39;Gao
Trident D&#39;Gao

Reputation: 19680

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.

Upvotes: 7

Will
Will

Reputation: 547

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

Upvotes: 1

WStrellis
WStrellis

Reputation: 171

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.

Upvotes: 17

Shegs84
Shegs84

Reputation: 13

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.

Upvotes: 0

Ravistm
Ravistm

Reputation: 2213

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

Upvotes: 15

Mukesh Singh Rathaur
Mukesh Singh Rathaur

Reputation: 13105

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

Upvotes: 2

user3300900
user3300900

Reputation: 81

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

Upvotes: 8

lsa77
lsa77

Reputation: 15

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

Upvotes: 0

Kemin Zhou
Kemin Zhou

Reputation: 6881

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

Upvotes: 7

Related Questions