Aws-cli: ImportError: No module named service

Created on 1 Apr 2015  路  10Comments  路  Source: aws/aws-cli

I'm getting the following error with version 1.7.16:

Traceback (most recent call last):
File "/usr/bin/aws", line 27, in
sys.exit(main())
File "/usr/bin/aws", line 23, in main
return awscli.clidriver.main()
File "/usr/lib/python2.6/site-packages/awscli/clidriver.py", line 47, in main
driver = create_clidriver()
File "/usr/lib/python2.6/site-packages/awscli/clidriver.py", line 56, in create_clidriver
event_hooks=emitter)
File "/usr/lib/python2.6/site-packages/awscli/plugin.py", line 49, in load_plugins
plugin.awscli_initialize(event_hooks)
File "/usr/lib/python2.6/site-packages/cwlogs/init.py", line 25, in awscli_initialize
from cwlogs.pull import initialize as logs_pull_init
File "/usr/lib/python2.6/site-packages/cwlogs/pull.py", line 22, in
from awscli.customizations.service import Service
ImportError: No module named service

[root@]# pip freeze | grep aws
awscli==1.7.16
awscli-cwlogs==1.1.1

I have ran "pip install awscli --force-reinstall --upgrade" with no change.

guidance

Most helpful comment

Where did you get awscli-cwlogs from?

  • I can't install it with pip
$ pip install awscli-cwlogs
Collecting awscli-cwlogs
  Could not find any downloads that satisfy the requirement awscli-cwlogs
  No distributions at all found for awscli-cwlogs

** Compare to https://pypi.python.org/pypi/awscli and you will see that if you scroll to the bottom there is a source file of awscli-1.7.18.tar.gz listed.

I'm gueesing the you can fix this with:

pip uninstall -y awscli-cwlogs
pip install awscli --force-reinstall --upgrade

All 10 comments

Where did you get awscli-cwlogs from?

  • I can't install it with pip
$ pip install awscli-cwlogs
Collecting awscli-cwlogs
  Could not find any downloads that satisfy the requirement awscli-cwlogs
  No distributions at all found for awscli-cwlogs

** Compare to https://pypi.python.org/pypi/awscli and you will see that if you scroll to the bottom there is a source file of awscli-1.7.18.tar.gz listed.

I'm gueesing the you can fix this with:

pip uninstall -y awscli-cwlogs
pip install awscli --force-reinstall --upgrade

Hello,

pip uninstall -y awscli-cwlogs
pip install awscli --force-reinstall --upgrade

After running the above commands, I get the following:

Traceback (most recent call last):
File "/usr/bin/aws", line 27, in
sys.exit(main())
File "/usr/bin/aws", line 23, in main
return awscli.clidriver.main()
File "/usr/lib/python2.6/site-packages/awscli/clidriver.py", line 47, in main
driver = create_clidriver()
File "/usr/lib/python2.6/site-packages/awscli/clidriver.py", line 56, in create_clidriver
event_hooks=emitter)
File "/usr/lib/python2.6/site-packages/awscli/plugin.py", line 44, in load_plugins
modules = _import_plugins(plugin_mapping)
File "/usr/lib/python2.6/site-packages/awscli/plugin.py", line 58, in _import_plugins
plugins.append(__import__(path))
ImportError: No module named cwlogs

Okay, so I can't figure out where your import of cwlogs is coming from. It's not in the project source for aws-cli or botocore.
https://github.com/aws/aws-cli/search?q=cwlogs
https://github.com/boto/botocore/search?q=cwlogs

Your stack trace (specifically: line 56, in create_clidriver)is very interesting to me because of another issue I am working on right now https://github.com/aws/aws-cli/issues/1261

Based on:
https://github.com/aws/aws-cli/blob/c0d866a86329343b1dab11dc853f6adedcdb9c4a/awscli/clidriver.py#L55-L56
It looks like you have a cwlogs plugin that is failing to load. Would you mind sharing the source of your ~/.aws/config file?
Mine is:

[default]
region = us-east-1
output = json
plugins = {"mycommand": "awsplugins.mycommand"}

and that plugins entry is one I added for a plugin I am working on. Did you intentionally add a cwlogs plugin?

@markfrancis905 The issue is that the awscli-cwlogs plugin you have installed is not compatible with the latest version of the CLI. I've reached out to the service team to coordinate getting that plugin updated. In the meantime, your two options are:

  1. Downgrade the CLI to an earlier version. I believe versions < 1.7.15 would work.
  2. Remove the cwlogs plugin if you're not using the aws logs ... high level commands.

For (2) you can disable the plugin by ensuring that your CLI config file (which defaults to ~/.aws/config) does not have the cwlogs plugin line:

[plugins]
cwlogs = ...       ; <-- you probably have a line like this in your cli config file.  just delete/comment this line out.

Let me know if you're still having issues.

This is somewhat unrelated to this ticket but characterized by a similar traceback (i.e. Google will bring you here), so I want to just leave this here... If you're getting ImportError: No module named main when you try to run aws from your commandline, you've installed the wrong library ... and you need to do pip uninstall -y aws && pip install awscli.

Maintainers please feel free to delete this comment if you think it's too irrelevant!

Not sure if it will work on your scenario but got it to work with:

pip install --upgrade --extra-index-url=http://aws-cloudwatch.s3-website-us-east-1.amazonaws.com/ --trusted-host aws-cloudwatch.s3-website-us-east-1.amazonaws.com awscli-cwlogs

most probably for version awscli-cwlogs-1.3.1.tar.gz on the url above

(Windows 7 64-bit and with the same result on Windows 10 64-bit)
I have EB-CLI and EC2-CLI installed and working.
I got the same issue, tried above command and got versions:

_Successfully installed awscli-1.7.27 awscli-cwlogs-1.3.2 bcdoc-0.14.0 botocore-0.108.0 jmespath-0.7.1 python-dateutil-2.4.2 rsa-3.1.4 six-1.10.0_

Any updates on what to do?

Hi Guy' s
I'm getting aws import error on production.
How to fix it?
Error>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@alu-alusb-staging:~# tail -f /edx/var/log/supervisor/lms-stderr.log
settings.INSTALLED_APPS # pylint: disable=pointless-statement
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named aws

@deepakd-perpetual
Log out and log back into the shell and the install is complete on userspace and virutalenv env.

Is this a feature or a bug?

I followed these steps:
Uninstall the awscli -- sudo pip uninstall -y awscli
remove lib cache -- sudo rm -rf /Library/Caches/*
Try installing awscli -- pip install awscli
got this error:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/botocore/__init__.py'

sudo chown -R userid:usergroup /Library/Python/2.7/site-packages/
pip install awscli
aws s3 ls -- worked smoothly.

Was this page helpful?
0 / 5 - 0 ratings