pip安装line_profiler失败

10 投票
2 回答
9862 浏览
提问于 2025-04-18 09:45

我输入了

sudo pip install "line_profiler"

然后我得到了

Downloading/unpacking line-profiler
  Could not find a version that satisfies the requirement line-profiler (from versions: 1.0b1, 1.0b2, 1.0b3)
Cleaning up...
No distributions matching the version for line-profiler
Storing debug log for failure in /home/milia/.pip/pip.log

当我用这个搜索 line_profile

sudo pip search "line_profiler"

我得到了:

django-debug-toolbar-line-profiler - A panel for django-debug-toolbar that integrates
                        information from line_profiler
line_profiler             - Line-by-line profiler.
tracerbullet              - A line-by-line profiler that doesn't suck.

不知道为什么,底线符号变成了“-”。我该怎么解决这个问题呢?

2 个回答

2

我安装了miniconda,然后运行了这个命令:

$ conda install -c anaconda line_profiler

13

问题不在于 pip 会把 _ 转换成 - 来符合包的命名要求,而是这个包目前处于 beta 状态,也就是说没有稳定的版本。换句话说,只有 beta 版本的链接可以在这个包的PyPI页面上找到。正如你所看到的,pip 是这样理解的:

Could not find a version that satisfies the requirement line-profiler (from versions: 1.0b1, 1.0b2, 1.0b3)

根据预发布版本的文档:

从版本1.4开始,pip 默认只会安装稳定版本,这些版本是根据PEP426的规定来确定的。如果一个版本无法被解析为符合PEP426的版本,那么它就会被认为是预发布版本。

你可以在使用 pip install 时加上--pre 参数:

--pre

包括预发布和开发版本。默认情况下,pip 只会找到稳定版本。

sudo pip install --pre line_profiler

或者,你也可以安装一个特定的版本:

sudo pip install line_profiler==1.0b3

撰写回答