Weird CPython 2.7 import traceback - not an ImportError

42 Views Asked by At

I have added directories to my sys.path hundreds of times before importing from them, and know what to expect from that. I confess, I don't have a lot of package or egg experience.

However, I have a somewhat special (apparently) directory that isn't working.

The traceback, when I try to import it, looks like:

Traceback (most recent call last):
  File "t", line 17, in <module>
    from InfinityUnixHost.activities.ICWrap import ICWrap
  File "/home/dstromberg/PycharmProjects/infinity_PY/src/InfinityUnixHost/activities/ICWrap.py",
line 8, in <module>
    from InfinityUnixHost.IPGlobal import DB_POOL
  File "/home/dstromberg/PycharmProjects/infinity_PY/src/InfinityUnixHost/IPGlobal.py",
line 12, in <module>
    INTERNAL_VERSION = pkg_resources.require("InfinityUnixHost")[0].version
  File "/home/dstromberg/virtualenvs/dev/local/lib/python2.7/site-packages/pkg_resources/__init__.py",
line 941, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/dstromberg/virtualenvs/dev/local/lib/python2.7/site-packages/pkg_resources/__init__.py",
line 828, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'InfinityUnixHost'
distribution was not found and is required by the application

And a tiny test program that produces this error is:

#!/usr/bin/env python

import sys
import os.path

sys.path.insert(0, os.path.abspath('src'))
sys.path.insert(0, os.path.abspath('eggs/InfinityCore-6-py2.7.egg'))
#for directory in sys.path:
#       # print(directory)
#       if \
#                       os.path.exists(os.path.join(directory,
'InfinityUnixHost')) and \
#                       os.path.exists(os.path.join(directory,
'InfinityUnixHost/activities')) and \
#                       os.path.exists(os.path.join(directory,
'InfinityUnixHost/activities/ICWrap.py')):
#               print('found in %s' % directory)

# from InfinityUnixHost.activities.ICWrap import ICWrap
from InfinityUnixHost.activities.ICWrap import ICWrap
dummy = ICWrap

BTW, the commented-out for loop can see the file I am trying to import (when uncommented), but still, the import machinery doesn't load the module.

I can't share much detail about the InfinityUnixHost internals unfortunately, but we can probably discuss it as needed.

Does anyone know why import is failing in this odd way? It's not even an ImportError!

BTW, I ran the test code until strace, and I could see it open ICWrap.py, but it still seems to have problems loading ICWrap.py into the interpreter.

Thanks!

1

There are 1 best solutions below

0
On

It turns out this is because some module-level code was doing something that tracebacked, so it just seemed like the import machinery was having trouble.