A következő címkéjű bejegyzések mutatása: AWS. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: AWS. Összes bejegyzés megjelenítése

2015. december 8., kedd

[SOLVED] Cent OS 7 ImportError: No module named cfnbootstrap

If you are trying to use Cloudformation init on CentOS7 or RedHat7, you may meet the following issue:
# /opt/aws/bin/cfn-init 
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 19, in <module>
    import cfnbootstrap
ImportError: No module named cfnbootstrap

Solution:
Validate, the cfnbootstrap is available by:
find / -name cfnbootstrap
/usr/lib/python2.7/dist-packages/cfnbootstrap

It means, the module is installed, but during import, python can not find it. 
Let's check the PYTHONPATH parameter, which defines the folders where to check for modules.

This is a simple way to list the directories:
# python2.7
Python 2.7.5 (default, Jun 24 2015, 00:41:19) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> /dist-packages
KeyboardInterrupt
>>> import sys
>>> print '\n'.join(sys.path)

/usr/lib64/python2.7/site-packages/gevent-1.0.1-py2.7-linux-x86_64.egg
/usr/lib/python2.7/site-packages/boto-2.36.0-py2.7.egg
/usr/lib/python2.7/site-packages/python_binary_memcached-0.24-py2.7.egg
/usr/lib64/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib/python2.7/site-packages
>>> 
As you can see, the module's containing folder (/usr/lib/python2.7/dist-packages/) is not listed here.

Now you have two options to solve this:
  1. Create a symbolic linc between the folders:
    ln -s /usr/lib/python2.7/dist-packages/cfnbootstrap /usr/lib/python2.7/site-packages/cfnbootstrap 
  2. Extend the PYTHONPATH parameter by adding the following line to /etc/environments:
    export PYTHONPATH="${PYTHONPATH}: /usr/lib/python2.7/dist-packages/"

I hope it helps.