convexengineering / gpfit

Fit posynomials to data
http://gpfit.readthedocs.io/en/latest/
MIT License
10 stars 7 forks source link

Can't import fit in the latest commit #65

Closed 1ozturkbe closed 7 years ago

1ozturkbe commented 7 years ago

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?

bqpd commented 7 years ago

it looks like you were in the gpfit folder? Shouldn't you import gpfit.fit?

1ozturkbe commented 7 years ago

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?

bqpd commented 7 years ago

Not if you were in the gpfit folder, or any folder with a file called fit.py

1ozturkbe commented 7 years ago

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?

bqpd commented 7 years ago

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...

1ozturkbe commented 7 years ago

K. Note taken, and lesson in imports learned. Thanks Ned, closing!

bqpd commented 7 years ago

https://www.python.org/dev/peps/pep-0328/#guido-s-decision and http://stackoverflow.com/a/11537218 have some details!