Can't import fit in the latest commit
Closed this issue · 7 comments
I am on commit 648d114, and was about to try to fit something very basic when I got the following error from trying import fit.
In [1]: import fit
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-b7a6b9d011b5> in <module>()
----> 1 import fit
C:\Users\Berk\Dropbox (MIT)\MIT Senior Year\16.82\gpfit\gpfit\fit.py in <module>()
2 from numpy import ones, exp, sqrt, mean, square, hstack
3 from gpkit import NamedVariables, VectorVariable, Variable, NomialArray
----> 4 from .implicit_softmax_affine import implicit_softmax_affine
5 from .softmax_affine import softmax_affine
6 from .max_affine import max_affine
ValueError: Attempted relative import in non-package
??? Help?
it looks like you were in the gpfit folder? Shouldn't you import gpfit.fit
?
poop. I need a lesson in libraries and importing instead. But why did it give the error above? I'm still confused about that; shouldn't it have failed outright?
Not if you were in the gpfit folder, or any folder with a file called fit.py
I am stupid... so please explain to me why I need to say import gpfit.fit
instead of just import fit
within the folder. Because I understand using from fit import fit
, but wouldn't import fit
just suffice?
in Python 2, import <filename in current directory>
will import that file directly, not as part of its package, so you get the non-package
error. Better to just never work directly in the gpfit repository unless you're actually editing gpfit code...
K. Note taken, and lesson in imports learned. Thanks Ned, closing!
https://www.python.org/dev/peps/pep-0328/#guido-s-decision and http://stackoverflow.com/a/11537218 have some details!