Why do I get "UserWarning: Module dap was already imported from None ..."
Asked Answered
C

3

14

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__)

What does this mean?

EDIT 1:

>>> import sys
>>> print sys.modules['dap']
<module 'dap' (built-in)>

EDIT 2:

$ 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'

EDIT 3: yes I seem to have 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

so this has nothing to do with mpl_toolkits.basemap as such.

Caneghem answered 17/12, 2012 at 13:39 Comment(4)
It means there is an entry sys.modules['dap'] that does not have a path. It's a warning, btw, not an exception, so it may be okay. What does print sys.modules['dap'] give you?Overreact
That means it has no filename; it automatically is marked as (built-in). Interesting, I wonder what poked that in there. Did you import anything or is that a clean python interpreter? Or did you import mpl_toolkits.basemap first?Overreact
It doesn't matter whether I import mpl_toolkits.basemap first or not, the result is the same.Caneghem
It matters to me. :-) It means that something on startup is poking that in; there could be a sitecustomize.py or usercustomize.py module somewhere that fiddles something. Try running python -S (disable site.py) and test sys.modules['dap'] again.Overreact
C
24

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.

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.

Caneghem answered 18/12, 2012 at 0:41 Comment(1)
As near as I can tell, this fix is correct, but it indicates a bug in the setup.py for the "dap" package.Wattmeter
W
2

I recently had to track down a similar problem, and the actual meaning of the error message:

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

Appears to be "While extending the path for 'dap', found an egg-info directory that does not declare 'dap' to be a namespace package".

This suggests two things: python-dap is missing a "namespace_packages=['dap']" declaration in its own setup.py, and setuptools really should give a better error message in this case...

Wattmeter answered 28/5, 2013 at 8:46 Comment(1)
Issue filed: bitbucket.org/pypa/setuptools/issue/2/…Wattmeter
C
0

If you don't need the package, simply remove it, e.g. on an Ubuntu or Debian system apt-get remove --purge python-dap removed the package for me and that silenced the warning. It is easy to accidentally install packages that you don't need because of dependency recommendations when installing some packages.

When you try to remove it the packaging system will warn you if removal of the package (in this case python-dap, but other packages could cause this error to happen, too) would also force removal of other packages which depend on it. In my case there are no other packages that directly depended on python-dap and I wasn't using it for anything that I was aware of, so uninstalling it was simple, painless, and silenced the warning.

Other package installers (such as the non-OS packaging systems like pip or easy_install) might make it more difficult to remove the package; you may need to delete the package by hand, so I'd instead recommend the accepted answer as the way to silence the warning unless the apt-get remove method I recommended here works for you.

Chkalov answered 17/12, 2013 at 2:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.