本文介绍了为什么我会收到"UserWarning:模块dap已从None导入..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Ubuntu软件包中安装了python-matplotlibpython-mpltoolkits.basemap.安装python-mpltoolkits.basemap还将安装python-dap作为依赖项.

I have python-matplotlib and python-mpltoolkits.basemap installed from Ubuntu packages. Installing python-mpltoolkits.basemap also installs python-dap as a dependency.

导入底图时,出现以下警告:

When I import basemap, I get this warning:

>>> import mpl_toolkits.basemap
/usr/lib/pymodules/python2.7/mpl_toolkits/__init__.py:2: UserWarning: Module dap was
already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
  __import__('pkg_resources').declare_namespace(__name__)

这是否意味着我安装了dap的2个冲突的安装? (这可能是某些旧的手动安装的残余.)此处是类似的警告消息,但在他的情况下,该消息告诉其他冲突的安装位置.我的消息只是说None.这是什么意思?

Does this mean I have 2 conflicting installs of dap? (That might be possible, remnants of some old manual installs.) Here is a somewhat similar warning message, but in his case the message tells where the other, conflicting, install is located. My message just says None. What does this mean?

>>> import sys
>>> print sys.modules['dap']
<module 'dap' (built-in)>
$ python -S
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2
>>> import sys
>>> print sys.modules['dap']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'dap'

是的,我似乎有sitecustomize.py:

$ cat /etc/python2.7/sitecustomize.py
# install the apport exception handler if available
try:
    import apport_python_hook
except ImportError:
    pass
else:
    apport_python_hook.install()

实际上我可以通过以下方式得到错误:

EDIT 4: actually I can get the error by:

>>> import pkg_resources
__main__:1: UserWarning: Module dap was already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path

因此这与mpl_toolkits.basemap无关.

推荐答案

我不能真的说我会理解细节,但是很显然,只要安装了软件包python-dap,然后尝试使用import pkg_resources都可以警告. 此处是一些讨论.

I can't really say that I'd understand the details, but apparently whenever the package python-dap is installed, then trying to import pkg_resources gives this warning. Here is some discussion.

遵循此处的建议(页面末尾的注释29),我在文件/usr/lib/python2.7/dist-packages/dap-2.2.6.7.egg-info/namespace_packages.txt的第一行中添加了dap,并且没有其他警告.希望这不会破坏任何东西.

Following advice from here (comment 29 at the end of the page), I added dap as the first line in file /usr/lib/python2.7/dist-packages/dap-2.2.6.7.egg-info/namespace_packages.txt and get no more warnings. Hope this does not break anything.

这篇关于为什么我会收到"UserWarning:模块dap已从None导入..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:11