1

I'm attempting to use imp.load_module to import a file I've created which relies on the pandas library. However, when importing the module an exception is thrown:

File "/usr/local/lib/python2.7/dist-packages/pandas/__init__.py", line 6, in 
     from . import hashtable, tslib, lib
    ImportError: cannot import name hashtable

The weird thing is that if I examine sys.modules, I can see the module is loaded:

{ ...
     'hashtable': <module 'pandas.hashtable' from '/usr/local/lib/python2.7/dist-packages/pandas/hashtable.so'>,
  ...
     'pandas.hashtable': <module 'pandas.hashtable' from '/usr/local/lib/python2.7/dist-packages/pandas/hashtable.so'>,
... }

Am I missing something? I'm unsure of what I can do from this point, and I'm wondering if this is somehow related to this issue.

Community
  • 1
  • 1
JesseBuesking
  • 6,496
  • 4
  • 44
  • 89
  • 1
    It looks like that error is raised by pandas itself. Does doing just `import pandas` work? – BrenBarn Jan 03 '14 at 20:21
  • From your `sys.modules`, it looks like you may have put `/usr/local/lib/python2.7/dist-packages/pandas/` on your `sys.path` as well as `/usr/local/lib/python2.7/dist-packages/` itself. Which can easily cause problems like this. If you don't know, can you dump out `sys.path` and see? – abarnert Jan 03 '14 at 20:43
  • My file does `import pandas`, so somehow this is within the actual import itself. I have logic to recursively import dependencies, which led me to discover that the `hashtable` module (and also the `tslib` and `lib` modules) was already imported. – JesseBuesking Jan 03 '14 at 20:52
  • @abarnert it looks like both *are* on my `sys.path`. I'll get it to stop that (use one *or* the other), and then report back on the outcome. – JesseBuesking Jan 03 '14 at 21:00
  • @JesseBuesking: Definitely eliminate the `dist-packages/pandas` on your path, not the `dist-packages`. You want to use `pandas` as a package, after all. – abarnert Jan 03 '14 at 21:12
  • possible duplicate of [Importing pandas shows ImportError: cannot import name hashtable](http://stackoverflow.com/questions/14422976/importing-pandas-shows-importerror-cannot-import-name-hashtable) – Andy Hayden Jan 03 '14 at 21:13
  • pandas wasn't built properly, how did you install it? – Andy Hayden Jan 03 '14 at 21:15
  • @abarnert I've temporarily altered my code to prevent `dist-packages/pandas` from being included on the path, but the issue persists. – JesseBuesking Jan 03 '14 at 21:39
  • @AndyHayden I spoke with the coworker who did the install, and they did in fact use pip. I think the issue is more-or-less tied to using `imp.load_source` to do the import. – JesseBuesking Jan 06 '14 at 17:28

0 Answers0