pip: --target doesn't work for namespace packages
When doing a local install of a namespace package, the .pth file doesn’t get picked up for some reason:
MAC-C08182:projects c08182$ mkdir targettest
MAC-C08182:projects c08182$ cd targettest/
MAC-C08182:targettest c08182$ pip install repoze.lru -t lib/
Downloading/unpacking repoze.lru
Downloading repoze.lru-0.6.tar.gz
Running setup.py (path:/private/var/folders/9w/_wt1czb57k9c5b0hgg6dfl2x7jbl85/T/pip_build_c08182/repoze.lru/setup.py) egg_info for package repoze.lru
Installing collected packages: repoze.lru
Running setup.py install for repoze.lru
Skipping installation of /var/folders/9w/_wt1czb57k9c5b0hgg6dfl2x7jbl85/T/tmp7uY1G8/lib/python/repoze/__init__.py (namespace package)
Installing /var/folders/9w/_wt1czb57k9c5b0hgg6dfl2x7jbl85/T/tmp7uY1G8/lib/python/repoze.lru-0.6-py2.7-nspkg.pth
Successfully installed repoze.lru
Cleaning up...
MAC-C08182:targettest c08182$ PYTHONPATH=$(pwd)/lib
MAC-C08182:targettest c08182$ python
Python 2.7.7 |Anaconda 2.0.0 (x86_64)| (default, Jun 2 2014, 12:48:16)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import repoze.lru
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named repoze.lru
>>>
MAC-C08182:targettest c08182$
However, all necessary files are in fact installed in lib/:
MAC-C08182:targettest c08182$ cd lib/
MAC-C08182:lib c08182$ ls
repoze repoze.lru-0.6-py2.7.egg-info
repoze.lru-0.6-py2.7-nspkg.pth
MAC-C08182:lib c08182$
And of course the whole procedure works just fine for non-namespace packages.
Thanks to @mmerickel for setting me straight on the source of the issue.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Disable nspkg.pth behavior on Python 3.3+. Fixes #805 and fixes pypa/pip#1924. — committed to pypa/setuptools by jaraco 8 years ago
- Update changelog. Fixes #250. Fixes #870. Ref #805. Ref pypa/pip#1924. Ref #845. — committed to pypa/setuptools by jaraco 8 years ago
@Ivoz
site.addsitedir('lib')was exactly what I needed. Thanks!@JensTimmerman That’s an interesting idea. I agree, it’s a bit hostile to install packages into a
--targetand then they not be viable without some additional steps.I’m not sure a warning is quite appropriate - as it may be the case that a tool invoking pip will be correcting for the condition as rwt does.
More importantly, though, this issue largely goes away with Python 3.3, so perhaps the best solution is just to work around it until you can port everything to Python 3.
So if I get this correct pip will not try to have a working namespace package when installed with --target? Could in this case some info (warning?) with some useful information be printed out to the user? e.g. pip doesn’t support this, you might want to run
code for workaround with site packageIn that latest thread, PJE says:
So checking if it’s the case:
So it seems that at least nominally pkg_resources is able to provide resources for the trivial package. Although,
I suspect that if the package had some metadata (dist-info or egg_info), it would also work. So I want to say PJE’s supposition is tenatively confirmed and focus on
Other interesting details in this thread.
Sadly, this not only affects
--target, but also--prefix… for now settled with the suggestion of @Ivoz, but this is ugly as hell:pip really should do something about it.
You could manually move the namespace’d package that you want to the actual folder where it would be located if it was simply part of the overall package, in a build / deploy step.
Alternately, call addsitedir explicitly in your own
sitecustomize.pyfile.