victorlei / smop

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

For dummies installation (Ubuntu) #149

Closed t2ac32 closed 2 years ago

t2ac32 commented 4 years ago

OK so I spent more time that I would like to admit trying to make smop run. These are some steps for a super easy installation in UBUNTU 18.04 using Anaconda.

Notes/Requirements: Anaconda (with anaconda navigator)

1: Open terminal:

option 1: CTRL +Alt +T option 2: app menu, search for terminal

2: Check which environment you are using.

(First word between parenthesis in your terminal lead text base in attached image) image

3: Open ANACONDA

If you are using "base" environment check if you have anaconda installed (attached image) image

4 Create new python2 environment

create a new environment for smop

option 1: Graphical method

option 2: Bash method:

To be safe lets update conda, type in terminal: conda update conda Replace this: conda create -n yourenvname python=x.x anaconda For this and write it in terminal and press enter: conda create -n smop python=2.7 anaconda

5 Activate newly created environment:

In terminal type: conda activate smop The text in parenthesis at the beggining of terminal should change to (smop) user@computername image

6 Install smop

In TERMINAL type: pip install smop You should see something like this at the end of the command and before the new line in terminal.

Successfully built smop networkx Installing collected packages: ply, numpy, scipy, decorator, networkx, smop Successfully installed decorator-4.4.0 networkx-2.2 numpy-1.16.5 ply-3.11 scipy-1.2.2 smop-0.41

FINALLY: Test version of smop

In terminal type: smop -V If this gives you a version you successfully installed smop, we are almost there!

CONVERT A FILE FROM matlab .m to PYTHON .p

Type in terminal : smop myMatlab.m

NOTE:

For this last command to work you should run the command in the folder where your .m file is located. In terminal go to the folder where the file you want to convert is saved (change directory command is your friend)

cd path/to/my/file.m

OR

Type smob in terminal (with your smob environment active) and drag and drop the file to convert from its location in to the terminal line where you are writing.

The Result .py file will appear in the same folder where the .m was dragged from.

Remember Every time you want to use smob you have to activate the environment where smob is installed. Just open the terminal check the first word between parenthesis if this word is not smob (or name given to the env in step 2) write in terminal conda activate smob

Hope this helps !

nasamaher commented 4 years ago

So standard Python packages on Ubuntu shouldn't be used? What version of Anaconda did you use?

BTW I had just installed with the following steps and smop fails with smop/benchmark5/benchmark2.m

apt install python-pip
pip install smop
t2ac32 commented 4 years ago

So standard Python packages on Ubuntu shouldn't be used? What version of Anaconda did you use?

BTW I had just installed with the following steps and smop fails with smop/benchmark5/benchmark2.m

apt install python-pip
pip install smop

The thing is that 90% (invented/exagerated satistic) of the time people using python is using python3 now a days. SMOP only works with python2 (and subversions).

So NO PYTHON3 for installing.

using pip to install this package will use your default version of python, or the default version of python of the virtual environment being used.

NOW to your problem: Could you run this in your terminal where you are running the "pip install smop" command: python -V and show us the result of the command.

nasamaher commented 4 years ago
mce@ubuntu18:~/Downloads/smop-master/smop/benchmark5$ python -V
Python 2.7.15+

Ubuntu 18 still defaults to Python2. To run Python you run python3

nasamaher commented 4 years ago

Below is the error I get with benchmark2.m.

mce@ubuntu18:~/Downloads/smop-master/smop/benchmark5$ smop -V
0.41
mce@ubuntu18:~/Downloads/smop-master/smop/benchmark5$ smop benchmark2.m 
WARNING: Couldn't open 'parser.out'. [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/smop/parser.out'
WARNING: Token 'END_UNEXPECTED' defined, but not used
WARNING: Token 'CLASSDEF' defined, but not used
WARNING: There are 2 unused tokens
Generating LALR tables
WARNING: Couldn't create 'smop.parsetab'. [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/smop/parsetab.py'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/smop/main.py", line 61, in main
    stmt_list = parse.parse(buf if buf[-1] == '\n' else buf + '\n')
  File "/usr/local/lib/python2.7/dist-packages/smop/parse.py", line 850, in parse
    buf, tracking=1, debug=options.debug_parser, lexer=new_lexer)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 331, in parse
    return self.parseopt(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 909, in parseopt
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python2.7/dist-packages/smop/parse.py", line 838, in p_error
    new_lexer)
  File "/usr/local/lib/python2.7/dist-packages/smop/lexer.py", line 338, in raise_exception
    my_lexer.lexdata[startpos:endpos]))
  File "benchmark2.m", line 5
    EMAIL : stefan@steinhaus
                   ^
SyntaxError: Unexpected "@" (parser)
Errors: 1
t2ac32 commented 4 years ago

Below is the error I get with benchmark2.m.

mce@ubuntu18:~/Downloads/smop-master/smop/benchmark5$ smop -V
0.41
mce@ubuntu18:~/Downloads/smop-master/smop/benchmark5$ smop benchmark2.m 
WARNING: Couldn't open 'parser.out'. [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/smop/parser.out'
WARNING: Token 'END_UNEXPECTED' defined, but not used
WARNING: Token 'CLASSDEF' defined, but not used
WARNING: There are 2 unused tokens
Generating LALR tables
WARNING: Couldn't create 'smop.parsetab'. [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/smop/parsetab.py'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/smop/main.py", line 61, in main
    stmt_list = parse.parse(buf if buf[-1] == '\n' else buf + '\n')
  File "/usr/local/lib/python2.7/dist-packages/smop/parse.py", line 850, in parse
    buf, tracking=1, debug=options.debug_parser, lexer=new_lexer)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 331, in parse
    return self.parseopt(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 909, in parseopt
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python2.7/dist-packages/smop/parse.py", line 838, in p_error
    new_lexer)
  File "/usr/local/lib/python2.7/dist-packages/smop/lexer.py", line 338, in raise_exception
    my_lexer.lexdata[startpos:endpos]))
  File "benchmark2.m", line 5
    EMAIL : stefan@steinhaus
                   ^
SyntaxError: Unexpected "@" (parser)
Errors: 1

This is not an installation related problem your installation is correct.

Your problem seems to be that you have characters in you .m file that can't be parsed by SMOP.

To be more specific line 5 in you .m file has an @ sign.

Either put that in a comment or try removing it for the conversion if it is not matlab code.

nasamaher commented 4 years ago

Thanks for the responses.

  1. My initial smop problem (I opened a short-term issue last week) was due to not having parentheses in a no-argument function definition (I'm a matlab newbie)
  2. I seem to have a functioning smop on Ubuntu after just the two install commands above (e.g., no Anaconda needed). I'm not 100% sure, because I see some oddities. For example, disp('here'), prints out ('here', ) (parentheses included) when running the Python. Minor issue.
  3. Concerning the '@' parsing error, I wasn't expecting an error in the benchmark2.m file within the smop distro but yes, there is an error in the current git version (c7f2637) (see below)

I'm going to go play with some real matlab code and see how things go.

Steve

%***************************************************************************
%* Matlab Benchmark program version 5.0 *
%* Author : Stefan Steinhaus *
%*
EMAIL : stefan@steinhaus
-
net.de *
%* This program is public domain. Feel free to copy it freely. *
%***************************************************************************
andreaconsole commented 4 years ago

I successfully installed it through pip, but then I always get a "not found" when I type smop in the terminal. Do I really need to install Anaconda on Kubuntu just to make it work?!

t2ac32 commented 4 years ago

I successfully installed it through pip, but then I always get a "not found" when I type smop in the terminal. Do I really need to install Anaconda on Kubuntu just to make it work?!

You don't need anaconda to make it work.

Also I haven't test in kubuntu just ubuntu.

Can you paste here your console log? This sounds like you installed but when running you are you using the wrong environment.

andreaconsole commented 4 years ago

Thanks for your reply. If I write smop in the shell, it is just an unknown command. Same if I call smop from Python3 or from Python2 (does it make any sense?). If I go with the shell to the smop directory and type "python2 main.py myfile.m -o myfile.py" I get an error message related to the relative imports. I tried to change every "from . import..." to "import" (because the files are there), and now I get no error. Nevertheless, still no output file is generated...

Il giorno lun 4 nov 2019 alle ore 02:41 Tracer notifications@github.com ha scritto:

I successfully installed it through pip, but then I always get a "not found" when I type smop in the terminal. Do I really need to install Anaconda on Kubuntu just to make it work?!

You don't need anaconda to make it work.

Also I haven't test in kubuntu just ubuntu.

Can you paste here your console log? This sounds like you installed but when running you are you using the wrong environment.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/victorlei/smop/issues/149?email_source=notifications&email_token=AAMRNO6GS73VYW5K3TPR4BTQR54TPA5CNFSM4I5X743KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC6CWKQ#issuecomment-549202730, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMRNO5KRH3RDEMXUWJ5K7TQR54TPANCNFSM4I5X743A .

abedin17 commented 2 years ago

I have created a virtual environment in conda but when i tried to check if smop is installed correctly I got this error--"module not found" . How can I fix it .Any suggestions. @t2ac32

(testsmopenv) C:\Users\Admin>smop -V Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\Scripts\smop-script.py", line 33, in sys.exit(load_entry_point('smop==0.31', 'console_scripts', 'smop')()) File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\Scripts\smop-script.py", line 25, in importlib_load_entry_point return next(matches).load() File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\importlib\metadata__init__.py", line 171, in load module = import_module(match.group('module')) File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\importlib__init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 992, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\site-packages\smop\init__.py", line 4, in import version ModuleNotFoundError: No module named 'version

t2ac32 commented 2 years ago

@abedin17 mmm. it's been a long time since I wrote this so many probably changed. For what I see you are trying to install in windows. This thread is for installing in Ubuntu (Linux).

abedin17 commented 2 years ago

Hi, thanks for replying. Well can you make one for windows that would be really helpful