How to import a module from PyPI when I have another module with the same name

Posted by kuzzooroo on Stack Overflow See other posts from Stack Overflow or by kuzzooroo
Published on 2014-06-01T21:23:22Z Indexed on 2014/06/01 21:24 UTC
Read the original article Hit count: 199

Filed under:
|
|
|

I'm trying to use the lockfile module from PyPI. I do my development within Spyder. After installing the module from PyPI, I can't import it by doing import lockfile. I end up importing anaconda/lib/python2.7/site-packages/spyderlib/utils/external/lockfile.py instead. Spyder seems to want to have the spyderlib/utils/external directory at the beginning of sys.path, or at least none of the polite ways I can find to add my other paths get me in front of spyderlib/utils/external.

I'm using python2.7 but with from __future__ import absolute_import.

Here's what I've already tried:

  1. Writing code that modifies sys.path before running import lockfile. This works, but it can't be the correct way of doing things.
  2. Circumventing the normal mechanics of importing in Python using the imp module (I haven't gotten this to work yet, but I'm guessing it could be made to work)
  3. Installing the package with something like pip install --install-option="--prefix=modules_with_name_collisions" package_name. I haven't gotten this to work yet either, but I'm guess it could be made to work. It looks like this option is intended to create an entirely separate lib tree, which is more than I need. Source
  4. Using pip install --target=lockfile_from_pip. The files show up in the directory where I tell them to go, but import doesn't find them. And in fact pip uninstall can't find them either. I get Cannot uninstall requirement lockfile-from-pip, not installed and I guess I will just delete the directories and hope that's clean. Source

So what's the preferred way for me to get access to the PyPI lockfile module?

© Stack Overflow or respective owner

Related posts about python

Related posts about import