开发者社区> 问答> 正文

ansible返回“未能导入所需的Python库(Docker SDK for Python: Do

我在ubuntu上运行我的服务器:

+ 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

我使用ansible,当我运行它,我得到以下错误:

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"}

当我运行

python -c "import sys; print(sys.path)"

我明白了:

['', '/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']

python版本如下:

+ python --version
Python 2.7.12
+ python3 --version
Python 3.5.2

然后,当我看到一切都很好,我不确定为什么我得到

"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"

在ansible吗? 问题来源StackOverflow 地址:/questions/59382861/cannot-install-python-in-a-specific-path-and-get-no-module-named-docker

展开
收起
kun坤 2019-12-27 16:59:02 4458 0
1 条回答
写回答
取消 提交回答
  • 似乎没有安装docker模块。 您需要通过系统包管理器(例如,apt安装python-docker)或使用pip安装它。 如果您有多个Python版本,请确保您已经将docker模块安装到Ansible正在使用的版本中。

    2019-12-27 16:59:10
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载