Connection between smop and networkx - different errors depending on versions of networkx

Viewed 12

I am new to python, and I found a matlab code online that I want to convert to python code using smop. I've installed smop, however when I try to run it I get an error.

When I have networkx version 1.11 I get the following error trying to run smop main.m

    Traceback (most recent call last):
  File "C:\Users\IDABUK\Anaconda3\envs\smop\lib\site-packages\smop\main.py", line 66, in main
    G = resolve.resolve(stmt_list)
  File "C:\Users\IDABUK\Anaconda3\envs\smop\lib\site-packages\smop\resolve.py", line 54, in resolve
    u = G.node[n]["ident"]
AttributeError: 'DiGraph' object has no attribute 'node'
Errors: 1

When I install a later version of networkx (pip install networkx==2.0 or pip install networkx==2.5) I get the following error:

    Traceback (most recent call last):
  File "C:\Users\IDABUK\Anaconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\IDABUK\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\IDABUK\Anaconda3\Scripts\smop.exe\__main__.py", line 4, in <module>
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\smop\main.py", line 17, in <module>
    from . import resolve
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\smop\resolve.py", line 22, in <module>
    import networkx as nx
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\networkx\__init__.py", line 114, in <module>
    import networkx.generators
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\networkx\generators\__init__.py", line 6, in <module>
    from networkx.generators.classic import *
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\networkx\generators\classic.py", line 26, in <module>
    from networkx.algorithms.bipartite.generators import complete_bipartite_graph
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\networkx\algorithms\__init__.py", line 16, in <module>
    from networkx.algorithms.dag import *
  File "C:\Users\IDABUK\Anaconda3\lib\site-packages\networkx\algorithms\dag.py", line 14, in <module>
    from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (C:\Users\IDABUK\Anaconda3\lib\fractions.py)

I am running this from the anaconda prompt window (anaconda power shell?).

Is there a way to fix this? The only solutions I find online are people installing various networkx-versions which does not seem like a solution for me in this case, or changing 'node' to 'nodes' directly in the code, however I can't find any instances of 'nodes' in the matlab code.

1 Answers

For people in the future looking for an answer: I could not find an answer for this.

However it worked using matlab2python. This is how it worked for me: In the terminal I wrote

git clone https://github.com/ebranlard/matlab2python
cd matlab2python
pip install -r requirements.txt

and then I used this code to convert each matlab-script:

python matlab2python/matlab2python.py file.m -o file.py
Related