pip 意外地没有安装带有 branch/commit 固定的 git 包的最新版本

pip unexpectedly not installing latest version of git package with branch/commit pinning

我有一个 requirements.txt 文件,其中包含以下行(以及其他内容):

git+https://github.com/lead-ratings/sexmachine.git@master#egg=SexMachine

当我做的时候

pip install -r requirements.txt

明白了

Requirement already satisfied (use --upgrade to upgrade): SexMachine from git+https://github.com/lead-ratings/sexmachine.git@master#egg=SexMachine in /home/myuser/virtual_env/lib/python2.7/site-packages (from -r requirements.txt (line 38))

并且软件包没有更新到主版本。实际上,它保留了我之前在 requirements.txt 中列出的 PyPI 的一些旧版本。

如果我在固定中指定提交或使用 --no-cache-dir 标志,它也不起作用。我正在使用 pip 6.1.1.

如果我使用 --upgrade 标志,那么它就可以工作。但是固定的意义何在?如果它真的不是,为什么它说 "Requirement already satisfied"?

Pip 仅根据版本号(在 setup.py 中)来决定是否满足要求。在您的情况下,您之前安装的 pypi 版本与 sexmachine 的 master 分支具有相同的版本号,因此 pip 什么也没做。

似乎解决这个问题的方法是始终传递 -U / --upgrade 标志:

pip install -r requirements.txt -U

维护者的职位在#2835中给出:

The behavior of pip here is correct then, we don't determine the version number of the project/file, that comes from inside the package. If they want to support arbitrary tags being independently identifiable they should have their setup.py adjust itself based on that.

在我的情况下,甚至 -U--upgrade 都不起作用。 Pip 还需要 setup.py 中的版本不同才能安装新版本。通过更新 setup.py 中的包版本,它起作用了。

我在创建一个 conda 环境时遇到了类似的问题,其中 pip 安装了 GitHub 上固定到特定提交的包。然后我想用 pip 将它固定到另一个提交来更新这个包。 -U 标志没有帮助。但是,--force-reinstall 标签做到了。