gpt4 book ai didi

python - 如何使用ansible正确升级pip?

转载 作者:行者123 更新时间:2023-12-01 08:26:57 25 4
gpt4 key购买 nike

目标和环境

我正在针对 Ubuntu 16.04 使用 ansible 。最终目标是使用mongodb_user模块。这需要 pymongo,因此这需要 python-pip

我在做什么

- name: Package prerequisites for pymongo ansible module
apt:
force_apt_get: yes
name: ['python-pip', 'python-setuptools']
install_recommends: no
state: present
become: true
tags:
- mongo
register: output

- name: Upgrade pip to latest vesion
pip:
name: pip
extra_args: --upgrade
register: output

- debug:
var: output

问题

这是实际输出;请注意:

  • 似乎pip忽略了升级指令
  • /usr/bin/pip2 二进制文件,而我正在期待
    "output": {
"changed": true,
"cmd": [
"/usr/bin/pip2",
"install",
"--upgrade",
"pip"
],
"failed": false,
"name": [
"pip"
],
"requirements": null,
"state": "present",
"stderr": "You are using pip version 8.1.1, however version 18.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.\n",
"stderr_lines": [
"You are using pip version 8.1.1, however version 18.1 is available.",
"You should consider upgrading via the 'pip install --upgrade pip' command."
],
"stdout": "Collecting pip\n Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl\nInstalling collected packages: pip\nSuccessfully installed pip-8.1.1\n",
"stdout_lines": [
"Collecting pip",
" Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl",
"Installing collected packages: pip",
"Successfully installed pip-8.1.1"
],
"version": null,
"virtualenv": null
}

奇怪的是,我从命令行得到了

$ /usr/bin/pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

$ /home/mirko/.local/bin/pip -V
pip 18.1 from /home/mirko/.local/lib/python2.7/site-packages/pip (python 2.7)

尝试一下

我尝试在安装 python-pip手动升级 pip 并遇到另一个奇怪的事情:pip 不想卸载旧的 pip...

sudo pip install pip --upgrade
[sudo] password for mirko:
The directory '/home/mirko/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mirko/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 1.2MB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr

问题

与 Ubuntu 16.04 相比,将 pip 与 ansible 结合使用的正确方法是什么?

我必须/可以强制ansible使用“我的”pip吗?

我必须/可以卸载“错误的”pip吗?

我是否做错了什么导致了这个双版本问题?

最佳答案

env:Ubuntu 18.04、Python 3.6.9、pip 最初位于 9.0.1

我最终做了以下事情:

    - name: pip self-update
pip:
name: pip
state: latest

参见doc about pip module

在运行 pip 要求安装之前,我自己完成了这一切。安装过程中出现了很多失败,而且 pip 太旧了,所以我想在进行其他安装之前额外确定一下。

这使我的 pip 数达到了 20.0.2 左右。

更大的上下文:我确实指定了一个 virtualenv,并且还通过 list 文件设置了 ansible_python_interpreter="/usr/bin/python3"

        virtualenv: "/srv/venv"

您可能需要也可能不需要做这些事情,重要的是要 200% 确定 pip 是合理的当前值。

关于python - 如何使用ansible正确升级pip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54179375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com