1

Premise: I use Python 3.9.0 on a MacOS with Mojave (version 10.14.5).

The paper "Network Inference via the Time-Varying Graphical Lasso" by David Hallac, Youngsuk Park, Stephen Boyd, Jure Leskovec comes with a Python code which can be found at https://github.com/davidhallac/TVGL. I tried to run the file exampleTVGL.py with Python IDLE but I have the following issues:

  • It seems to be written in Python2 language, so I converted it in Python3 language with 2to3 command in the terminal;
  • Then, when running exampleTVGL.py I got the error:
"SyntaxError: import * only allowed at module level"

which I tried to solve by replacing:

from <modulename> import *

with

import <modulename>

*** update: not even this point is working, cannot substitute like this in order to import all from a module; How, so?

  • Then two modules were missing (snap and cvxpy), so I installed them in the terminal;
  • Last I got the error:
NameError: name 'TUNGraph' is not defined

I see that David Hallac himself on GitHub issues page suggests to solve the error by installing snap package, but on my computer the requirement is already satisfied and still not working.

What am I doing wrong? I tried use Python2, but was not able to install it, although not sure this would be sufficient to solve all issues. How can I solve the NameError 'TUNGraph" problem? Do you have any suggestion on how could I run more efficiently the code without experimenting issues?

Thank you

Barbab
  • 266
  • 1
  • 8
  • 1
    you may need to prefix function calls with the name of the module. For instance: `modulename.TUNGraph()` instead of `TUNGraph` – Pac0 Mar 28 '21 at 11:08
  • I get `class TGraphVX(snap.TUNGraph()):AttributeError: module 'snap' has no attribute 'TUNGraph'` – Barbab Mar 28 '21 at 11:15
  • 1
    it's possible that, unfortunately, these external libraries are not equivalent between their python 2 / 3 versions. – Pac0 Mar 28 '21 at 19:53
  • Is it possible to switch to python 2 version of these libraries? – Barbab Mar 30 '21 at 09:15
  • 1
    ok, I tried to install python2 and the required libraries on windows, but unfortunately I ended lost with mismatched version of some visualC+ tools to be able to install cvxpy. Since you're on macOS I hope you'll have more chance. In theory, to install python2 libraries, you have to be careful in using **pip2 install** instead of pip install. If you're lucky, this could simply solve your issue. – Pac0 Mar 30 '21 at 20:40
  • 1
    (sidenote) Ha! I was trying to google something to help you install python2 alongside python3 on macos, but I found [the question you just asked](https://stackoverflow.com/questions/66868705/both-python-2-and-python-3-installed-on-macos-but-pip-command-install-libraries) instead – Pac0 Mar 30 '21 at 20:46
  • 1
    can you check using `pip2` instead of `pip` ? Seems to me python installs those aliases by default, useful in this case. If this doesn't exist, we can create it – Pac0 Mar 30 '21 at 20:47
  • 1
    also you can try https://stackoverflow.com/a/38043109/479251 (see "method 2 from 2019" in the linked answer) – Pac0 Mar 30 '21 at 20:51
  • pip2 does not work. Actually I think I will give up on using python 2 and try to make the code work with python 3 – Barbab Mar 31 '21 at 09:55
  • 1
    It was already hard to get python2 and python3 working together, but now that python2 is deprecated, lots of libraries are not getting updated as well, and it can become a nightmare. Good luck for your port, if you can make it work it will probably be very helpful to inform on TVGL's github page as well! – Pac0 Mar 31 '21 at 10:08

0 Answers0