awscli fails to work: No module named 'awscli&

2019-04-18 00:57发布

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.

10条回答
三岁会撩人
2楼-- · 2019-04-18 01:22

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楼-- · 2019-04-18 01:22

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.
查看更多
Fickle 薄情
4楼-- · 2019-04-18 01:22

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.

查看更多
霸刀☆藐视天下
5楼-- · 2019-04-18 01:25

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
查看更多
登录 后发表回答