awscli fails to work: No module named 'awscli'

偶尔善良 提交于 2019-12-09 14:18:25

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



回答4:


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




回答5:


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



回答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.



回答7:


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




回答8:


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



回答9:


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



回答10:


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



回答11:


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



回答12:


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.




回答13:


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.



来源:https://stackoverflow.com/questions/43873663/awscli-fails-to-work-no-module-named-awscli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!