victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

Import errors when running #136

Open EvilxFish opened 5 years ago

EvilxFish commented 5 years ago

Using arch linux, cloned the repo so most up to date version I hope, followed as per instructions:

$ cd smop/smop $ python main.py solver.m $ python solver.py

get error after second instruction:

Traceback (most recent call last): File "main.py", line 15, in from . import options ImportError: cannot import name 'options' from 'main' (main.py)

EvilxFish commented 5 years ago

Note by changing the import statements as suggested elsewhere I did get the program to run without errors however "solver.py" was not generated meaning something else is going wrong...

hcji commented 5 years ago

same error

hcji commented 5 years ago

retry on py 2.7.16, not fix

RobBW commented 5 years ago

I struck the same problem 2 days ago while running “futurize" http://python-future.org/overview.html#futurize-2-to-both http://python-future.org/overview.html#futurize-2-to-both over the smop 0.41package to identify a problem caused by a mixture of calls to --builtin— (python2) rather than builtins (python3).

“ futurize” also introduces the . .. & … notation into import calls thereby setting up potential absolute vs relative path problems.

Facts of life about Python Modules are well explained in: Relative paths in Python - Stack Overflow https://stackoverflow.com/questions/918154/relative-paths-in-python

I think you have run into a problem with absolute vs relative paths in the smop import statements because import options is the first relative call when smop is run. This may have arisen because of the recent upgrade of smop to run on python3.

You’ll find the kind of problem you have reported explained within the following 3 links from StackOverflow:

Python Relative Import cannot find package - Stack Overflow https://stackoverflow.com/questions/38645486/python-relative-import-cannot-find-package python - How to fix "Attempted relative import in non-package" even with init.py - Stack Overflow https://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py?rq=1 https://stackoverflow.com/questions/918154/relative-paths-in-python https://stackoverflow.com/questions/918154/relative-paths-in-python

If I’m right, you should be able to avoid, but not solve, your problem by running setup and then calling smop rather than calling main.py

How to fix the smop code itself isn’t clear. The links above suggest so many options.

Hope this is all helpful, I haven’t had time to try it yet.

Regards Rob

RobBWilkinson@gmail.com

On 27/03/2019, at 00:52, EvilxFish notifications@github.com wrote:

Using arch linux, cloned the repo so most up to date version I hope, followed as per instructions:

$ cd smop/smop $ python main.py solver.m $ python solver.py

get error:

Traceback (most recent call last): File "main.py", line 15, in from . import options ImportError: cannot import name 'options' from 'main' (main.py)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/136, or mute the thread https://github.com/notifications/unsubscribe-auth/AGLYJn7PO6aJCzPK7Y-_2xN6psdF6DIRks5vagoNgaJpZM4cLQAs.

Codeguyross commented 5 years ago

Note by changing the import statements as suggested elsewhere I did get the program to run without errors however "solver.py" was not generated meaning something else is going wrong...

I am also having the error of of smop not generating output

orena1 commented 4 years ago

Use this fork: https://github.com/PatrickFURI/smop