Skip to content

Commit 1d8b167

Browse files
committed
Prefer local package imports in examples and clarify TF env errors
1 parent 168e91c commit 1d8b167

7 files changed

Lines changed: 51 additions & 8 deletions

File tree

examples/alias.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import sys
2+
from pathlib import Path
3+
14
import matplotlib.pyplot as plt
25
import numpy as np
36

7+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
8+
if str(PROJECT_ROOT) not in sys.path:
9+
sys.path.insert(0, str(PROJECT_ROOT))
10+
411
from ge.alias import alias_sample, create_alias_table
512

613

examples/deepwalk_wiki.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from pathlib import Path
2+
import sys
23

34
import matplotlib.pyplot as plt
45
import networkx as nx
56
import numpy as np
67
from sklearn.linear_model import LogisticRegression
78
from sklearn.manifold import TSNE
89

10+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
11+
if str(PROJECT_ROOT) not in sys.path:
12+
sys.path.insert(0, str(PROJECT_ROOT))
13+
914
from ge import DeepWalk
1015
from ge.classify import Classifier, read_node_label
1116

12-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1317
WIKI_GRAPH_PATH = PROJECT_ROOT / "data" / "wiki" / "Wiki_edgelist.txt"
1418
WIKI_LABEL_PATH = PROJECT_ROOT / "data" / "wiki" / "wiki_labels.txt"
1519
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

examples/line_wiki.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
from pathlib import Path
2+
import sys
23

34
import matplotlib.pyplot as plt
45
import networkx as nx
56
import numpy as np
67
from sklearn.linear_model import LogisticRegression
78
from sklearn.manifold import TSNE
89

9-
from ge import LINE
10+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
11+
if str(PROJECT_ROOT) not in sys.path:
12+
sys.path.insert(0, str(PROJECT_ROOT))
13+
14+
try:
15+
from ge import LINE
16+
except ImportError as exc:
17+
raise ImportError(
18+
"Unable to import LINE. Use a supported Python/TensorFlow environment "
19+
"(for example Python 3.10-3.12 with tensorflow installed)."
20+
) from exc
1021
from ge.classify import Classifier, read_node_label
1122

12-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1323
WIKI_GRAPH_PATH = PROJECT_ROOT / "data" / "wiki" / "Wiki_edgelist.txt"
1424
WIKI_LABEL_PATH = PROJECT_ROOT / "data" / "wiki" / "wiki_labels.txt"
1525
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

examples/node2vec_flight.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from pathlib import Path
2+
import sys
23

34
import matplotlib.pyplot as plt
45
import networkx as nx
56
import numpy as np
67
from sklearn.linear_model import LogisticRegression
78
from sklearn.manifold import TSNE
89

10+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
11+
if str(PROJECT_ROOT) not in sys.path:
12+
sys.path.insert(0, str(PROJECT_ROOT))
13+
914
from ge import Node2Vec
1015
from ge.classify import Classifier, read_node_label
1116

12-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1317
FLIGHT_GRAPH_PATH = PROJECT_ROOT / "data" / "flight" / "brazil-airports.edgelist"
1418
FLIGHT_LABEL_PATH = PROJECT_ROOT / "data" / "flight" / "labels-brazil-airports.txt"
1519
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

examples/node2vec_wiki.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from pathlib import Path
2+
import sys
23

34
import matplotlib.pyplot as plt
45
import networkx as nx
56
import numpy as np
67
from sklearn.linear_model import LogisticRegression
78
from sklearn.manifold import TSNE
89

10+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
11+
if str(PROJECT_ROOT) not in sys.path:
12+
sys.path.insert(0, str(PROJECT_ROOT))
13+
914
from ge import Node2Vec
1015
from ge.classify import Classifier, read_node_label
1116

12-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1317
WIKI_GRAPH_PATH = PROJECT_ROOT / "data" / "wiki" / "Wiki_edgelist.txt"
1418
WIKI_LABEL_PATH = PROJECT_ROOT / "data" / "wiki" / "wiki_labels.txt"
1519
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

examples/sdne_wiki.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
from pathlib import Path
2+
import sys
23

34
import matplotlib.pyplot as plt
45
import networkx as nx
56
import numpy as np
67
from sklearn.linear_model import LogisticRegression
78
from sklearn.manifold import TSNE
89

9-
from ge import SDNE
10+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
11+
if str(PROJECT_ROOT) not in sys.path:
12+
sys.path.insert(0, str(PROJECT_ROOT))
13+
14+
try:
15+
from ge import SDNE
16+
except ImportError as exc:
17+
raise ImportError(
18+
"Unable to import SDNE. Use a supported Python/TensorFlow environment "
19+
"(for example Python 3.10-3.12 with tensorflow installed)."
20+
) from exc
1021
from ge.classify import Classifier, read_node_label
1122

12-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1323
WIKI_GRAPH_PATH = PROJECT_ROOT / "data" / "wiki" / "Wiki_edgelist.txt"
1424
WIKI_LABEL_PATH = PROJECT_ROOT / "data" / "wiki" / "wiki_labels.txt"
1525
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

examples/struc2vec_flight.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
import sys
23
import tempfile
34

45
import matplotlib.pyplot as plt
@@ -7,10 +8,13 @@
78
from sklearn.linear_model import LogisticRegression
89
from sklearn.manifold import TSNE
910

11+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
12+
if str(PROJECT_ROOT) not in sys.path:
13+
sys.path.insert(0, str(PROJECT_ROOT))
14+
1015
from ge import Struc2Vec
1116
from ge.classify import Classifier, read_node_label
1217

13-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
1418
FLIGHT_GRAPH_PATH = PROJECT_ROOT / "data" / "flight" / "brazil-airports.edgelist"
1519
FLIGHT_LABEL_PATH = PROJECT_ROOT / "data" / "flight" / "labels-brazil-airports.txt"
1620
SMOKE_GRAPH_PATH = PROJECT_ROOT / "tests" / "Wiki_edgelist.txt"

0 commit comments

Comments
 (0)