0

I use ansible to build docker image and I get the following error:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on dd63315fad06's Python /usr/bin/python. Please read module documentation and install in the appropriate location, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named docker"}

when I do the sudo python -c "import sys; print(sys.path)"

I see this:

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/pip-19.2.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/fasteners-0.15-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/monotonic-1.5-py2.7.egg', '/usr/lib/python2.7/dist-packages']

So I do not see any path like this /usr/bin/python and I assume that python is not installed in the right folder. So I decided to install python in /usr/bin/python and make it a default one: Here is I have:

sudo apt-get install -y python3-pip \
  && cd /usr/bin \
  && sudo ln -s /usr/bin/python3 python #\

but still I see that the python is not installed /usr/bin/python:

Here is what I see in for python:

['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

The operating system I am using is:

which os:

+ sudo cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Any idea?

Lucan
  • 2,907
  • 2
  • 16
  • 30
Learner
  • 1,686
  • 4
  • 19
  • 38
  • 1
    What python version are you trying to install? I see python2.7 in the error log and `sys.path` and python3 in `apt-get install` – S.Au.Ra.B.H Dec 17 '19 at 23:59
  • @saurjog I am trying to install whatever version that I can get rid of that ansible bug. Does that not mean that python has not been installed in the specified folder for ansible? – Learner Dec 18 '19 at 00:21
  • This appears to be a duplicate. If it's not, please update the question so that it's clear how this question is different from the linked one. In both cases, there is nothing in the question that shows you are installing the `docker` module for Python on your target host. – larsks Dec 18 '19 at 05:12

0 Answers0