Python 为什么 pip 安装我的包的旧版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14617136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:58:43  来源:igfitidea点击:

Why is pip installing an old version of my package?

pythonpipsetuptools

提问by brianmearns

I've just uploaded a new version of my package to PyPi (1.2.1.0-r4): I can download the egg file and install it with easy_install, and the version checks out correctly. But when I try to install using pip, it installs version 1.1.0.0 instead. Even if I explicitly specify the version to pip with pip install -Iv tome==1.2.1.0-r4, I get this message: Requested tome==1.2.1.0-r4, but installing version 1.1.0.0, but I don't understand why.

我刚刚将我的包的新版本上传到 PyPi (1.2.1.0-r4):我可以下载 egg 文件并使用 easy_install 安装它,并且版本检查正确。但是当我尝试使用 pip 安装时,它会安装 1.1.0.0 版。即使我明确指定了 pip 的版本pip install -Iv tome==1.2.1.0-r4,我也会收到以下消息:Requested tome==1.2.1.0-r4, but installing version 1.1.0.0,但我不明白为什么。

I double checked with parse_versionand confirmed that the version string on 1.2.1 is greater than that on 1.1.0 as shown:

我仔细检查parse_version并确认 1.2.1 上的版本字符串大于 1.1.0 上的版本字符串,如下所示:

>>> from pkg_resources import parse_version as pv
>>> pv('1.1.0.0') < pv('1.2.1.0-r4')
True
>>>

So any idea why it's choosing to install 1.1.0 instead?

那么知道为什么它选择安装 1.1.0 吗?

采纳答案by Matt Fenwick

This is an excellent question. It took me forever to figure out. This is the solution that works for me:

这是一个很好的问题。我花了很长时间才弄明白。这是对我有用的解决方案:

Apparently, if pipcan find a local version of the package, pipwill prefer the local versions to remote ones. I even disconnected my computer from the internet and tried it again -- when pipstill installed the package successfully, and didn't even complain, the source was obviously local.

显然,如果pip可以找到包pip的本地版本,则更喜欢本地版本而不是远程版本。我什至断开了我的计算机与互联网的连接并再次尝试 - 当pip仍然成功安装软件包并且甚至没有抱怨时,源显然是本地的。

The really confusing part, in my case, was that pipfound the newer versions on pypi, reported them, and then went ahead and re-installed the older version anyway ... arggh. Also, it didn't tell me what it was doing, and why.

就我而言,真正令人困惑的部分是pippypi上找到较新版本,报告它们,然后继续并重新安装旧版本...... arggh。此外,它没有告诉我它在做什么,以及为什么。

So how did I solve this problem?

那么我是如何解决这个问题的呢?

You can get pipto give verbose output using the -vflag ... but one isn't enough. I RTFM-ed the help, which said you can do -vmultiple times, up to 3x, for more verbose output. So I did:

您可以pip使用-v标志提供详细的输出......但一个是不够的。我对帮助进行了 RTFM 编辑,其中说您可以-v多次执行,最多 3 次,以获得更详细的输出。所以我做了:

pip install -vvv <my_package>

Then I looked through the output. One line caught my eye:

然后我查看了输出。有一句话引起了我的注意:

Source in /tmp/pip-build-root/ has version 0.0.11, which satisfies requirement <my_package>

/tmp/pip-build-root/ 中的源版本为 0.0.11,满足 <my_package> 要求

I deleted that directory, after which pipinstalled the newest version from pypi.

我删除了那个目录,然后pip从 pypi 安装了最新版本。

回答by Ruth

Got the same issue to update pika 0.9.5 to 0.9.8. The only working way was to install from tarball: pip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gz.

将 pika 0.9.5 更新到 0.9.8 时遇到了同样的问题。唯一的工作方法是从 tarball 安装:pip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gz.

回答by simplylizz

I found herethat there is a known bug in pip that it won't check the version if there's a build directory with unpacked sources. I have checked this on my troubling package and after deleting its sources from build directory pip installed the required version.

我在这里发现pip 中存在一个已知错误,如果存在带有解压源的构建目录,它不会检查版本。我已经在我的麻烦包上检查了这一点,并从构建目录 pip 中删除了它的源代码后,安装了所需的版本。

回答by Piotr Dobrogost

Thanks to Marcus Smith, who does amazing work as a maintener of pip, this was fixed in version 1.4 of pip which was released on 2013-07-23.

感谢Marcus Smith作为 pip 的维护者做了惊人的工作,这个问题在 2013 年 7 月 23 日发布的 pip 1.4 版中得到了修复。

Relevant information from the changelogfor this version

此版本变更日志中的相关信息

Fixed a number of issues (#413, #709, #634, #602, and #939) related to cleaning up and not reusing build directories. (Pull #865, #948)

修复了许多与清理和不重用构建目录相关的问题(#413、#709、#634、#602 和 #939)。(拉#865、#948)

回答by ribozz

If you are using a pipversion that comes with some distribution packages (ex. Ubuntu python-pip), you may need to install a newer pipversion:

如果您使用的pip是某些分发包附带的版本(例如 Ubuntu python-pip),您可能需要安装更新的pip版本:

Update pipto latest version:

更新pip到最新版本:

sudo pip install -U pip

sudo pip install -U pip

In case of "virtualenv", skip "sudo":

在“virtualenv”的情况下,跳过“sudo”:

pip install -U pip

pip install -U pip

Following command may be required, if your shell report something like -bash: /usr/bin/pip: No such file or directoryafter pipupdate:

如果您的 shell-bash: /usr/bin/pip: No such file or directorypip更新后报告类似内容,则可能需要以下命令:

hash -d pip

hash -d pip

Now install your package as usual:

现在像往常一样安装你的包:

pip install -U foo

pip install -U foo

or

或者

pip install foo==package.version.here

pip install foo==package.version.here

回答by Iacchus

Try forcing download the package again with:

尝试使用以下命令再次强制下载软件包:

pip install --no-cache-dir --upgrade <package>

回答by mlissner

I found that if you use microversions, pip doesn't seem to recognize them. For example, we couldn't get version 1.9.9.1 to upgrade.

我发现如果您使用微版本,pip 似乎无法识别它们。例如,我们无法升级 1.9.9.1 版本。

回答by Alberto Chiusole

In my case the python version used (3.4) didn't satisfy Django 2.1 dependencies requirements (python >= 3.5).

在我的情况下,使用的 python 版本 (3.4) 不满足 Django 2.1 依赖项要求 (python >= 3.5)。

回答by NateW

For my case I had to delete the .pipfolder in my home directory and then I was able to get later versions of multiple libraries. Note that this was on linux.

就我而言,我必须删除.pip主目录中的文件夹,然后才能获得多个库的更高版本。请注意,这是在 linux 上。

pip --version
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
virtualenv --version
15.1.0

回答by Cheen

In my case I am pip installing a .tar.gz package from Artifactory that I make a lot of updates to. In order to overwrite my cached Python files and always grab/install the latest I was able to run:

就我而言,我正在从 Artifactory 安装一个 .tar.gz 包,我对其进行了大量更新。为了覆盖我缓存的 Python 文件并始终获取/安装我能够运行的最新文件:

pip install --no-cache-dir --force-reinstall <path/to/tar.gz>

pip install --no-cache-dir --force-reinstall <path/to/tar.gz>

You should see this re-download any necessary files and install those, instead of using your local cache.

您应该会看到重新下载任何必要的文件并安装它们,而不是使用本地缓存。