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

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_namespace...
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-nam...
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

What do you mean by "using"? You mean installing them (for which you should never use easy_install anyway, btw), or packaging them? The only limitation regarding packaging them is that you currently need to explicitly list them in your packaging configuration, as find_packages() does not yet support namespace packages.
Thomas Nyberg kirjoitti 24.10.2017 klo 16:01:
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_namespace...
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-nam...
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 _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig

On 10/25/2017 04:54 PM, Alex Grönholm wrote:
What do you mean by "using"?
Are you referring to where I say "I'm currently using python 3.5 as packaged in debian 9"? (I can't find the string "using" anywhere else.) I just mean that that is the version of python I have installed.
You mean installing them (for which you
should never use easy_install anyway, btw), or packaging them? The only limitation regarding packaging them is that you currently need to explicitly list them in your packaging configuration, as find_packages() does not yet support namespace packages.
At this point I mean installing them using the `setup.py` script that is in that repo (i.e. executing `python3 setup.py install`). I mean this file: https://github.com/pypa/sample-namespace-packages/blob/master/native/pkg_a/s...) That file is using setuptools.
Maybe the best way to formulate my question is: Should the steps that I put in the previous email result in error or not? I.e. is that a bug or expected behavior.
Thanks for the help.
Cheers, Thomas

Ok, I get you now. So, what you should be doing is using pip to install them ("pip install ."). Directly doing "setup.py install" will install .egg files which are a thing of the past. Do this and the verify script will work fine.
I hope this answers your question.
Thomas Nyberg kirjoitti 25.10.2017 klo 22:05:
On 10/25/2017 04:54 PM, Alex Grönholm wrote:
What do you mean by "using"?
Are you referring to where I say "I'm currently using python 3.5 as packaged in debian 9"? (I can't find the string "using" anywhere else.) I just mean that that is the version of python I have installed.
You mean installing them (for which you
should never use easy_install anyway, btw), or packaging them? The only limitation regarding packaging them is that you currently need to explicitly list them in your packaging configuration, as find_packages() does not yet support namespace packages.
At this point I mean installing them using the `setup.py` script that is in that repo (i.e. executing `python3 setup.py install`). I mean this file: https://github.com/pypa/sample-namespace-packages/blob/master/native/pkg_a/s...) That file is using setuptools.
Maybe the best way to formulate my question is: Should the steps that I put in the previous email result in error or not? I.e. is that a bug or expected behavior.
Thanks for the help.
Cheers, Thomas _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
participants (2)
-
Alex Grönholm
-
Thomas Nyberg