NWChemEx / .github

GitHub Settings for the NWChemEx Organization
https://nwchemex.github.io/.github/
Apache License 2.0
1 stars 2 forks source link

Import weirdness #34

Open ryanmrichard opened 2 years ago

ryanmrichard commented 2 years ago

Admittedly I'm pretty weak when it comes to the mechanics of Python's import mechanism, so this might be a Python error on my side.

Anyways, since this works:

import simde

mol = simde.chemist.Molecule()

I would have expected:

import simde.chemist as chemist

mol = chemist.Molecule()

to work. Instead I get ModuleNotFoundError: No module named 'simde.chemist'. Assuming this isn't a problem with my Python, I think what's happening is that the Chemist found by SimDE isn't actually a Python module (i.e., it doesn't have an __init__.py file). Interestingly:

import simde
import chemist

mol = simde.chemist.Molecule()
mol = chemist.chemist.Molecule()

works which suggests to me that we might have a Python stack where each module x includes copies of the repos below it, instead of simply than importing them as submodules.

I'm going to throw this issue in the .github repo, but it should be moved to the appropriate repo if .github isn't it.

wadejong commented 2 years ago

This is a standard Python feature. The solution that we need to use is "from x import y". Hence:

from simde import chemist 

mol = chemist.Molecule() 

Others that work:

from chemist import chemist

from nwchemex import chemist

ryanmrichard commented 2 years ago

I don't think this is the same as #31. I think this is a problem with us actually copying the subpackages instead of importing them.