pip显示包版本不正确
我不太确定这是个bug,还是我做错了什么。情况是这样的,
pip list -o
这段代码会列出一些过时的Python包,以及它们应该是当前安装的版本。问题是,我很确定它给我的某些包的信息是错误的。比如下面这个例子,pip认为我安装的ipython版本是2.0.0,但当我在命令提示符下运行ipython时,显示的版本是2.1.0。
kolmogorov:~# pip list -o | head -15
Warning: cannot find svn location for PEAK-Rules==0.5a1.dev-r2707
Warning: cannot find svn location for prioritized-methods==0.2.2dev-20110830
scipy (Current: 0.13.2 Latest: 0.14.0)
plotly (Current: 1.0.30 Latest: 1.0.32)
SOAPpy (Current: 0.12.21 Latest: 0.12.22)
openpyxl (Current: 1.8.6 Latest: 2.0.3)
networkx (Current: 1.8.1 Latest: 1.9)
setuptools (Current: 3.4.1 Latest: 5.1)
brewer2mpl (Current: 1.3.2 Latest: 1.4)
repoze.who (Current: 1.0.19 Latest: 2.2)
pandas (Current: 0.13.1 Latest: 0.14.0)
pygeocoder (Current: 1.2.2 Latest: 1.2.5)
ipython (Current: 2.0.0 Latest: 2.1.0)
tornado (Current: 3.2 Latest: 3.2.2)
Could not find any downloads that satisfy the requirement vboxapi
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 235, in main
return command.main(cmd_args)
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 156, in main
logger.fatal('Exception:\n%s' % format_exc())
File "/usr/lib/python2.7/dist-packages/pip/log.py", line 111, in fatal
self.log(self.FATAL, msg, *args, **kw)
File "/usr/lib/python2.7/dist-packages/pip/log.py", line 164, in log
consumer.flush()
IOError: [Errno 32] Broken pipe
kolmogorov:~# ipython
Python 2.7.7 (default, Jun 3 2014, 16:16:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
我的问题是:有没有办法让pip正确识别已安装的Python包的版本?
2 个回答
2
你可以运行以下命令来查看这个软件包的来源:
which ipython
还有:
pip show ipython
你可能有两个安装版本:一个是通过 pip install ipython
安装的,另一个是通过其他工具安装的(比如在Linux上的包管理器,或者在Mac上的Ports/brew)。
1
要正确解决这个问题,其实比我想象的要复杂一些,但我必须把它作为正确的答案提交,因为它确实能解决问题。
假设你在使用 pip
时,遇到的问题是关于 pandas
这个包的版本。你观察到的情况是:
pip list --outdated
系统显示你安装的 pandas
版本是 0.14.0
;但是当你在比如 ipython
中查询 pandas
的版本时:
In [1]: import pandas
In [2]: pandas.__version__
Out[2]: '0.14.1'
为了修复这个问题,你可以按照以下步骤操作:
- 运行
pip show pandas
;这条命令会告诉你这个包的安装位置,比如我这里是/usr/local/lib/python2.7/dist-packages
- 切换到那个位置,输入
cd /usr/local/lib/python2.7/dist-packages
- 运行
ls -lstrh pandas-0.14.*
;你应该能看到与你的0.14.1
版本和想要删除的0.14.0
版本相关的文件 - 运行
rm -rf pandas-0.14.0*.egg-info pandas-0.14.0*.pth
来删除这些文件
这样就可以了!
pip show pandas
现在应该能和 pandas.__version__
的结果一致了