[Distutils] How do native namespaces work? (And do they play well with setuptools?)

Thomas Nyberg tomuxiong at gmx.com
Tue Oct 24 09:01:14 EDT 2017


Hello,

I previously posted this to python-list as well as reddit:

	https://mail.python.org/pipermail/python-list/2017-October/726935.html
	https://www.reddit.com/r/learnpython/comments/78emwr/how_to_native_namespaces_work_in_python_35/

So far (as pointed out in the reddit link I posted) it seems like maybe
I can't use native namespaces in conjunction with setuptools and must
instead use pip. Is this correct?

Here is my original message which contains all the details:

I'm trying to understand native namespaces. I'm currently using python
3.5 as packaged in debian 9. I've been following the instructions here:

	https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages

Those instructions link to the following example:

	https://github.com/pypa/sample-namespace-packages/tree/master/native

I presume I'm doing something silly, but I can't get that to work. I've
tried creating a virtual environment as:

--------------------------------------------------
$ python3 -m venv venv
$ source venv/bin/activate
--------------------------------------------------

_Note_: The virtual environment is active, but I'm stripping the (venv)
off the prompt below to shorten the lines.

And then I've gone into those repo folders and run their setup.py files
(e.g. for namespace a):

--------------------------------------------------
$ cd sample-namespace-packages/native/pkg_a/
$ python3 setup.py install
--------------------------------------------------

Then if I try to run their sample verification file, things fail:

--------------------------------------------------
$ cat sample-namespace-packages/verify_packages.py
from example_pkg import a
from example_pkg import b

print(a.name)
print(a.__path__)
print(b.name)
print(b.__path__)
$ python3 sample-namespace-packages/verify_packages.py
Traceback (most recent call last):
  File "sample-namespace-packages/verify_packages.py", line 1, in <module>
    from example_pkg import a
ImportError: No module named 'example_pkg'
--------------------------------------------------

Things seem to be installing:

--------------------------------------------------
$ ls venv/lib/python3.5/site-packages/
easy-install.pth           pkg_resources
easy_install.py            pkg_resources-0.0.0.dist-info
example_pkg_a-1-py3.5.egg  __pycache__
example_pkg_b-1-py3.5.egg  setuptools
pip                        setuptools-32.3.1.dist-info
pip-9.0.1.dist-info
--------------------------------------------------

Am I missing something totally obvious here? Does anyone here see what
I'm doing wrong? Thanks for any help!

Cheers,
Thomas


More information about the Distutils-SIG mailing list