-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Environment
- pip version: 18.0
- Python version: 2.7.15
- OS: Gentoo Linux
Description
When setup.py
depends on pkg_resources
namespace package, ImportError
happens during pip wheel
build process. This happens only with Python2 because Python3 supports native namespace packages and .pth
files machinery is not required.
Expected behavior
Expected for package to be built successfully and expected ability to use namespace packages in setup.py
.
How to Reproduce
Consider package depending on package using pkg_resources
namespace packages, for example let it be google.protobuf
.
setup.py
:
from setuptools import find_packages, setup
# this is for example only, actually some setup helper is imported
import google.protobuf
setup(
name='p',
version='1.0',
description='namespace packages not supported',
packages=find_packages(),
)
pyproject.toml
:
[build-system]
requires = [
"setuptools",
"wheel",
"protobuf",
]
p/__init__.py
is empty.
Output
~/env/bin/pip wheel .
Processing /home/daa/tmp/2
Installing build dependencies ... done
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-jy9sib/setup.py", line 4, in <module>
import google.protobuf
ImportError: No module named google.protobuf
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-jy9sib/
My reasoning
This happens because pkg_resources
-style namespace packages rely on *.pth
files being executed on Python startup, but those files are looked for only in site directory. pip
sets up build environment by installing packages to some prefix and setting PYTHONPATH
. So that directory is not considered as sitedir and thus pth-files from that location are not executed and namespace packages are not set up properly which leads to inability to import them.