简体   繁体   English

为什么 pip 安装的是旧版本的 package?

[英]Why is pip installing an old version of my package?

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.我刚刚将我的 package 的新版本上传到 PyPi (1.2.1.0-r4):我可以下载 egg 文件并使用 easy_install 安装它,并且版本正确检查。 But when I try to install using pip, it installs version 1.1.0.0 instead.但是当我尝试使用 pip 安装时,它会安装 1.1.0.0 版本。 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.即使我使用pip install -Iv tome==1.2.1.0-r4明确指定 pip 的版本,我也会收到此消息: Requested tome==1.2.1.0-r4, but installing version 1.1.0.0 ,明白为什么。

I double checked with parse_version and 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 吗?

This is an excellent question.这是一个很好的问题。 It took me forever to figure out.我花了很长时间才弄明白。 This is the solution that works for me:这是对我有用的解决方案:

Apparently, if pip can find a local version of the package, pip will prefer the local versions to remote ones.显然,如果pip可以找到包的本地版本,则pip会更喜欢本地版本而不是远程版本。 I even disconnected my computer from the internet and tried it again -- when pip still installed the package successfully, and didn't even complain, the source was obviously local.我什至断开了我的计算机与互联网的连接并再次尝试 - 当pip仍然成功安装软件包并且甚至没有抱怨时,源显然是本地的。

The really confusing part, in my case, was that pip found the newer versions on pypi , reported them, and then went ahead and re-installed the older version anyway ... arggh.就我而言,真正令人困惑的部分是pippypi上找到了较新版本,报告了它们,然后继续并重新安装了旧版本...... arggh。 Also, it didn't tell me what it was doing, and why.此外,它没有告诉我它在做什么,以及为什么。

So how did I solve this problem?那么我是如何解决这个问题的呢?

You can get pip to give verbose output using the -v flag ... but one isn't enough.您可以使用-v标志让pip提供详细的输出......但一个是不够的。 I RTFM-ed the help, which said you can do -v multiple times, up to 3x, for more verbose output.我对帮助进行了 RTFM,其中说您可以多次执行-v ,最多 3 次,以获得更详细的输出。 So I did:所以我做了:

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 pip installed the newest version from pypi.我删除了那个目录,之后pip从 pypi 安装了最新版本。

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

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

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 changelog for this version此版本变更日志中的相关信息

Fixed a number of issues (#413, #709, #634, #602, and #939) related to cleaning up and not reusing build directories.修复了许多与清理和不重用构建目录相关的问题(#413、#709、#634、#602 和 #939)。 (Pull #865, #948) (拉#865、#948)

I found here that there is a known bug in pip that it won't check the version if there's a build directory with unpacked sources.我在这里发现 pip 中存在一个已知错误,如果存在带有解压源的构建目录,它不会检查版本。 I have checked this on my troubling package and after deleting its sources from build directory pip installed the required version.我已经在我的麻烦包上检查过这个,在从构建目录中删除它的源代码后,pip 安装了所需的版本。

If you are using a pip version that comes with some distribution packages (ex. Ubuntu python-pip), you may need to install a newer pip version:如果您使用的是某些分发包(例如 Ubuntu python-pip)附带的pip版本,则可能需要安装更新的pip版本:

Update pip to latest version:更新pip到最新版本:

sudo pip install -U pip

In case of "virtualenv", skip "sudo":在“virtualenv”的情况下,跳过“sudo”:

pip install -U pip

Following command may be required, if your shell report something like -bash: /usr/bin/pip: No such file or directory after pip update:如果您的 shell 报告类似-bash: /usr/bin/pip: No such file or directory after pip update 之类的内容,则可能需要以下命令:

hash -d pip

Now install your package as usual:现在像往常一样安装你的包:

pip install -U foo

or要么

pip install foo==package.version.here

Got the same issue to update pika 0.9.5 to 0.9.8.将 pika 0.9.5 更新到 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 .唯一可行的方法是从 tarball pip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gzpip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gz

For my case I had to delete the .pip folder in my home directory and then I was able to get later versions of multiple libraries.就我而言,我必须删除主目录中的.pip文件夹,然后才能获得多个库的更高版本。 Note that this was on linux.请注意,这是在 linux 上。

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

I found that if you use microversions, pip doesn't seem to recognize them.我发现如果您使用微版本,pip 似乎无法识别它们。 For example, we couldn't get version 1.9.9.1 to upgrade.例如,我们无法升级 1.9.9.1 版本。

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

In my case I am pip installing a .tar.gz package from Artifactory that I make a lot of updates to.就我而言,我正在从 Artifactory 安装一个 .tar.gz 包,我对其进行了大量更新。 In order to overwrite my cached Python files and always grab/install the latest I was able to run:为了覆盖我缓存的 Python 文件并始终获取/安装我能够运行的最新文件:

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.您应该会看到重新下载任何必要的文件并安装它们,而不是使用本地缓存。

In my case, someone had published the latest version of a package with python2, so attempting to pip3 install it grabbed an older version that had been built with python3.在我的情况下,有人出版了最新版本python2一包的,因此试图pip3 install它抓住的是已经建成与python3旧版本。

Handy things to check when debugging this:调试时要检查的方便事项:

  • If pip install claims to not be able to find the version, see whether pip search can see it.如果pip install声称找不到版本,看看pip search是否可以看到。
  • Take a look at the "Download Files" section on the pypi repo -- the filenames might suggest what's wrong (in my case i saw -py2- there clear as day).看看 pypi 存储库上的“下载文件”部分——文件名可能表明出了什么问题(在我的情况下,我看到-py2-那里很清楚)。
  • As suggested by others, try running pip install --no-cache-dir in case pip isn't bothering to ask the internet because it already has your answer locally.正如其他人所建议的那样,尝试运行pip install --no-cache-dir以防 pip 不费心询问互联网,因为它已经在本地有了您的答案。

I had hidden unversioned files under the Git tab in PyCharm that were being installed with pip install .我在 PyCharm 的 Git 选项卡下隐藏了未版本控制的文件,这些文件是通过pip install . even though I didn't see the files anywhere else.即使我在其他任何地方都没有看到这些文件。

Took a long time to find it for me, posting this in hope that it'll help somebody else.找了好久才找到,贴出来希望能帮到别人。

Just in case that anyone else hassles with upgrading torchtext (or probably any other torch library):以防万一其他人在升级火炬文本(或可能是任何其他torch库)时遇到麻烦:

Although https://pypi.org/project/torchtext/ states that you could run pip install torchtext I had to install it similiar to torch by specifying --find-links aka -f :尽管https://pypi.org/project/torchtext/声明您可以运行pip install torchtext我必须通过指定--find-links aka -f来安装它--find-links torch

pip install torchtext===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

What irritated me was that PyCharm pointed me to the new version, but couldn't find it when attempting to upgrade to it.令我恼火的是 PyCharm 将我指向新版本,但在尝试升级到它时找不到它。 I guess that PyCharm uses its own mechanism to spot new versions.我猜想 PyCharm 使用自己的机制来发现新版本。 Then, when invoking pip under the hood, it didn't find the new version without the --find-links option.然后,当在--find-links调用pip时,它没有找到没有--find-links选项的新版本。

if you need the path for your package do pip -v list .如果您需要 package 的路径,请执行pip -v list Example see related post when using pip -e Why is an old version of a package of my python library installing by itself with pip -e?使用 pip -e 时的示例见相关帖子为什么我的 python 库的 package 的旧版本是使用 Z682AD1C2A456D8Z 自行安装的?

10 years on and pip still fails to work as expected. 10 年过去了, pip仍然无法按预期工作。

I wasted a couple of hours now banging my head against the wall trying to find out why pip won't install a development version of my package.我现在浪费了几个小时的头撞墙试图找出为什么pip不会安装我的 package 的开发版本。 In my case, there are versions 0.0.4 and 0.0.5.dev1 in a private gitlab.com package registry (hence the --extra-index-url argument below), but I believe that's not relevant to the problem. In my case, there are versions 0.0.4 and 0.0.5.dev1 in a private gitlab.com package registry (hence the --extra-index-url argument below), but I believe that's not relevant to the problem.

Following a lot of the advice on this page, I create a test venv in a far away folder, clear the pip cache, uninstall the package in question, etc. first to rule out the most common problems:按照这个页面上的很多建议,我在一个很远的文件夹中创建了一个测试venv,清除pip缓存,卸载有问题的package等,首先排除最常见的问题:

$ pip cache purge && \
  pip uninstall --yes my-package && \
  pip install --extra-index-url "https://_:${GITLAB_PASSWORD_TOOLS_VAULTTOOLS}@gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple" \
              --no-cache-dir  \
              --pre           \
              --upgrade my-package

output (using empty lines to separate output for commands): output(使用空行分隔 output 用于命令):

WARNING: No matching packages
Files removed: 0

Found existing installation: my-package 0.0.4
Uninstalling my-package-0.0.4:
  Successfully uninstalled my-package-0.0.4

Looking in indexes: https://pypi.org/simple, https://_:****@gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple
Collecting my-package
  Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/f07 ... 397/my_package-0.0.5.dev1-py3-none-any.whl (16 kB)
  Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/775 ... 70e/my_package-0.0.4-py3-none-any.whl (16 kB)
    ...
Successfully installed my-package-0.0.4

So pip does see the dev package version, but chooses the earlier one nonetheless.所以pip确实看到了 dev package 版本,但仍然选择了较早的版本。

In an attempt to figure out what's going on, I published a 0.0.5 version: Error persists, pip sees all three versions, but still installs 0.0.4 .为了弄清楚发生了什么,我发布了一个0.0.5版本:错误仍然存在, pip看到所有三个版本,但仍然安装0.0.4

In a further, increasingly desperate attempt, I removed any versions prior to 0.0.5* from the gitlab.com package registry.在进一步的、越来越绝望的尝试中,我从 gitlab.com package 注册表中删除了0.0.5*之前的所有版本。

Only now , pip would bother to actually display some useful information:只是现在pip才会费心实际显示一些有用的信息:

$ (same command as above)
    ... (similar output as above) ...
ERROR: Cannot install my-package==0.0.5 and my-package==0.0.5.dev1 because these package versions have conflicting dependencies.

The conflict is caused by:
    my-package 0.0.5 depends on my-other-package<0.2.5 and >=0.2.4
    my-package 0.0.5.dev1 depends on my-other-package<0.2.5 and >=0.2.4

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

OK, so there is something wrong with my package dependencies.好的,所以我的 package 依赖项有问题。 Thanks for letting me know.谢谢你让我知道。

Seriously - I tried hard for a couple of hours using all kinds of pip... -vvv and/or fixed versions such as eg my-package==0.0.5.dev1 - but I did not manage to get any useful output out of pip - until I wiped the entire history from my package registry.说真的 - 我使用各种pip... -vvv和/或固定版本(例如my-package==0.0.5.dev1 )努力了几个小时 - 但我没有设法得到任何有用的 output pip - 直到我从我的 package 注册表中擦除整个历史记录。

Hope this at least helps someone in the same situation.希望这至少可以帮助处于相同情况的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM