7

PEP 423 states that project names and package names should be the same and later gives an example where the project/package name contains a dot:

Yes:
Package name: "kheops.pyramid", i.e. import kheops.pyramid
Project name: "kheops.pyramid", i.e. pip install kheops.pyramid

What would the directory structure be for kheops.pyramid and how would setup.py be written (specifically the name and packages values) for that directory structure?

I've also seen that PEP 503 states that names should be normalized by replacing _, -, and . with -. Does this mean that kheops-pyramid should be used rather than kheops.pyramid? If so, wouldn't I need a package whose directory name is kheops-pyramid and wouldn't the - cause issues (eg. syntax error) when trying to import kheops-pyramid?

EDIT:
I tried to make a project/package kheops.pyramid to adhere to PEP 423 but I cannot figure out what directory structure and setup.py combination will allow me to import kheops.pyramid after pip install kheops.pyramid without an error like ImportError: No module named kheops.pyramid.

Community
  • 1
  • 1
Pedro Cattori
  • 2,735
  • 1
  • 25
  • 43
  • Have you looked at *"namespace packages"*? See e.g. https://www.python.org/dev/peps/pep-0420/ – jonrsharpe Jun 11 '16 at 16:13
  • @jonrsharpe I had not seen PEP 420 before. It definitely seems relevant but not sure I understand how to address my problem still. – Pedro Cattori Jun 11 '16 at 17:08
  • What *is* your problem? Are you trying to make a package with a `.` in the name and failing? – jonrsharpe Jun 11 '16 at 17:11
  • @jonrsharpe yes. i am trying to make a project/package like `username.package` to adhere to PEP 423 https://www.python.org/dev/peps/pep-0423/#top-level-namespace-relates-to-code-ownership but I cannot figure out what directory structure and `setup.py` combination will allow me to `import username.package` after `pip install username.package` without an error like `ImportError: No module named username.package`. Will edit the question to make this more apparent. – Pedro Cattori Jun 11 '16 at 17:33
  • You need `kheops` to exist first in order for `kheops.pyramid` to be possible. – tripleee Jun 12 '16 at 06:58
  • @tripleee not sure what type of thing `kheops` is in your comment: project, package, directory? – Pedro Cattori Jun 12 '16 at 14:50
  • A package, I guess. Tangentially, see also stackoverflow.com/questions/7948494/whats-the-difference-between-a-python-module-and-a-python-package – tripleee Jun 12 '16 at 15:58

2 Answers2

1

PEP 423 is deferred, so I ended doing to equivalent of pyramid rather than kheops.pyramid via standard python packaging. Here is the package I came up with as an example.

Pedro Cattori
  • 2,735
  • 1
  • 25
  • 43
0

from username import package should work.

Are you sure about your PYTHONPATH ?

You might want to try executing the system commands after PYTHONPATH=. ? This is because you perhaps haven't set PYTHONPATH to include the directory which contains username/

You might also want to check Python Package Structure.

Community
  • 1
  • 1
trishnag
  • 182
  • 1
  • 3
  • 13