2

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?

Community
  • 1
  • 1
kuzzooroo
  • 6,788
  • 11
  • 46
  • 84
  • Next option: don't use Spyder. But adjusting `sys.path` to remove the `spyderlib/utils/external` path from it or moving it down is the next best thing. – Martijn Pieters Jun 01 '14 at 21:32
  • A good example of why you shouldn't tamper with sys.path in packages – Ben DeMott Jun 02 '14 at 07:48
  • I've gone with #1 as @MartijnPieters suggests. But isn't this a problem that could pop up whether or not I'm using Spyder? It doesn't seem crazy that there could be two different libraries named "lockfile" that one might want to have installed in the same Python environment. – kuzzooroo Jun 02 '14 at 11:52
  • @kuzzooroo: Yes, this is a general problem, and why one should use namespaces were you can. Top-level name clashes can and do happen. – Martijn Pieters Jun 02 '14 at 11:56
  • @kuzzooroo: I am singling Spyder out here as it is an IDE; I feel strongly that such an IDE should be more careful in not polluting the top-level namespace with such generic names. – Martijn Pieters Jun 02 '14 at 11:57

0 Answers0