How to use SMOP to convert Matlab into Python code
Asked Answered
D

2

15

I've installed SMOP via pip and it seemed to work fine. I have smop-script.py and smop.exe files in my python folder \scripts\ folder.

Let's say I have a matlab file called myMatlabFile.m located in C:\Users\MyMatlabCode. How do I use smop to translate that file?

The SMOP documentation only includes an example of opening a file contained in a \smop\ folder with a main.py and I don't have anything like that. Also, the github page doesn't say whether it works only with 2.7 or 3. or whatever.

I was hoping that this package would speed up my Matlab -> Python 3.6 conversion, but if there are better translators out there now please let me know that too/instead.

Displease answered 19/4, 2018 at 10:14 Comment(2)
Have you tried asking the creators of the package?Naseby
Yes, but no response to that thread on its GitHub page for a couple of weeks.Displease
P
11

I just tried using to convert a matlab file with SMOP and it worked. I installed the software using pip in Anaconda Prompt environment.

pip install smop

After the installation I had the 0.41 Version.

I copied the file that I wanted to convert in the folder where I ran the pip code in the Anaconda Prompt environment.

Then I used the code smop and the file name .m and got a file .py in the same folder.

smop VI.m
Pancratium answered 10/9, 2018 at 23:17 Comment(7)
If you get an error on converting the file: AttributeError: 'DiGraph' object has no attribute 'node' install pip install networkx==1.11 It's because Networkx v2 is somewhat non-backward compatible with smop (quite outdated)Expulsive
After installing networkx==1.11 I get ...networkx\algorithms\dag.py", line 2, in <module> from fractions import gcd ImportError: cannot import name gcd from fractionsFungible
@Fungible For later who ran into the same problem after using pip install networkx==1.11. I solved the problem by Editing the source file "...\lib\site-packages\networkx\algorithms\dag.py." Remove the import statement and replace the gcd occurrences with math.gcdBias
@Bias could you please provide more details please? I get the same problem, but I don't get, which import statement to remove and how to replace the gcd occurences with math.gcdRingsmuth
@JuliaKoncha Remove the import statement of gcd and replace the gcd occurences with math.gcd using text editors.Bias
@Tab1e, thank you! For those who also need the detailed answer, I followed steps described here github.com/smicallef/spiderfoot/issues/1124 and it worked well:)Ringsmuth
!pip install networkx==1.3 avoids the gcd import issue in Python 3Skipton
B
2

Using smop is not different from the other command line tools. First, obtain the sources. Download, clone, tar, wget, or whatever works for you. Let's call the directory containing setup.py the root directory. Change directory to that one. Now install smop

> pip install .

Let's see if it works:

> smop -V

0.40

Yup, it does.

Let's see the docs:

> smop | more

At last, the translation itself. If you have a bunch of Matlab m files, named foo.m, bar.m , bzz.m and you want to translate these files to python you type

> smop foo.m bar.m bzz.m
Bani answered 26/5, 2018 at 15:23 Comment(1)
I appreciate the response, but it's not actually helpful. You assume too much about our knowledge of how these things work, and you don't address any of the details in the original question. I don't doubt that your explanation is enough for you to understand how to use smop, but it's not enough for many other people.Displease

© 2022 - 2024 — McMap. All rights reserved.