How do native namespaces work?
Peter Otten
__peter__ at web.de
Thu Oct 5 10:07:48 EDT 2017
Thomas Nyberg wrote:
> Hello,
>
> 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
> --------------------------------------------------
>
> 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
Are you sure you are using the correct interpreter? When I activate a
virtual environment it changes the prompt like so:
$ python3 -m venv venv
$ . venv/bin/activate
(venv) $
(venv) $ which python3
/home/peter/venv/bin/python3
(venv) $ deactivate
$
$ which python3
/usr/bin/python3
> --------------------------------------------------
>
> 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 Python-list
mailing list