1

I am packaging a python package using conda-build and ran into some issues. I am probably missing something fundamental and would appreciate if you could point me in the right direction.

The package looks like

|foo
  |meta.yaml
  |build.sh
  |build.bat
  |foo
    |__init__.py
    |module_1
    |module_2
    |-submodule
        |module_3
        |__init__.py
    |setup.py

module_1 looks like

import module_2

def fun:
    print(module2.__name__)

If I import the package from a parent folder like:

from foo import module_1

I get the error: module_2 not found

If I rewrite the import like import foo.module_2 everyhting works fine. Is this the proper way to handle inter package imports ?

Moritz
  • 5,130
  • 10
  • 40
  • 81
  • Try a relative import like `from . import module_2`. If this is Python 3, absolute imports like `import module_2` would not be treated as package-relative. – Iguananaut Nov 05 '18 at 10:14
  • Also I'm not sure if it's just a mistake in your formatting, but your ASCII art makes it look like you have a `setup.py` *inside* the package. It should be outside the package. – Iguananaut Nov 05 '18 at 10:15
  • That is another thing i currently try to understand. I guess I should try conda skeleton – Moritz Nov 05 '18 at 10:19
  • What is it that you don't understand? – Iguananaut Nov 05 '18 at 10:21
  • I get `/home/moritz/anaconda3/conda-bld/cadet_match_1541412717213/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/bin/python: can't open file 'setup.py': [Errno 2] No such file or directory` when setup.py is in the parent directory. I guess something in the meta.yaml is wrong. I will make another questions and reference here. – Moritz Nov 05 '18 at 10:24
  • It might has to to something with the ${PREFIX} variable. and how conda_build.sh is generated – Moritz Nov 05 '18 at 10:26
  • 1
    Probably a problem in your conda stuff. `setup.py` should *never* go inside a package, and should only be at the root level of your source tree. It *describes* a package but is not part of the package. – Iguananaut Nov 05 '18 at 10:30

0 Answers0