Search code examples
pythonpipsetuptoolspkg-resources

Can't get rid of a ghost module


So this is a weird one... I admit, I install my own module with a wild mix of

  • python setup.py install
  • python setup.py develop
  • pip install .
  • pip install -e .

but I cannot identify the source of a remaining ability to import my module (planet4) after having used 'pip uninstall' and manually removed any remaining eggs or egg-links, or even entries in *.pth files.

I tried the obvious: planet4.__file__ but that's empty:

In [12]: planet4.__file__
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-09c196cdfffe> in <module>()
----> 1 planet4.__file__

AttributeError: module 'planet4' has no attribute '__file__'

Python still thinks this is a module:

In [16]: type(planet4)
Out[16]: module

and when I try to use pkg_resources to get to some hidden file paths I get the weirdest error that even Google only has seen a couple of times, at least related to removing a package:

In [10]: import pkg_resources as pr
In [11]: pr.resource_exists('planet4', 'data')
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-11-3ac559fe861b> in <module>()
----> 1 pr.resource_exists('planet4', 'data')

/Users/klay6683/miniconda3/envs/py35/lib/python3.5/site-packages/setuptools-19.6.2-py3.5.egg/pkg_resources/__init__.py in resource_exists(self, package_or_requirement, resource_name)
   1137     def resource_exists(self, package_or_requirement, resource_name):
   1138         """Does the named resource exist?"""
-> 1139         return get_provider(package_or_requirement).has_resource(resource_name)
   1140
   1141     def resource_isdir(self, package_or_requirement, resource_name):

/Users/klay6683/miniconda3/envs/py35/lib/python3.5/site-packages/setuptools-19.6.2-py3.5.egg/pkg_resources/__init__.py in has_resource(self, resource_name)
   1603
   1604     def has_resource(self, resource_name):
-> 1605         return self._has(self._fn(self.module_path, resource_name))
   1606
   1607     def has_metadata(self, name):

/Users/klay6683/miniconda3/envs/py35/lib/python3.5/site-packages/setuptools-19.6.2-py3.5.egg/pkg_resources/__init__.py in _has(self, path)
   1658     def _has(self, path):
   1659         raise NotImplementedError(
-> 1660             "Can't perform this operation for unregistered loader type"
   1661         )
   1662

NotImplementedError: Can't perform this operation for unregistered loader type

Anybody has anymore ideas what I could try?


Solution

  • Open a python prompt

    import sys
    
    for p in sys.path:
        print p
    

    That will give you a list of directories. Go look in all of them for a directory or file with the name planet4. Also look for any .pth files. If you find any, open them in a text editor, they will give you more directories to look in, rinse and repeat.