Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: "yield from " produces syntax error

Tags:

python

I'm using the Gaston Frequent Subgraph Mining implementation by Njissen on Ubuntu 16.04 and tried it both on Python 3.6.5 and 2.7.15rc1. When executing the program I get a

Traceback (most recent call last):
  File "/home/elias/.local/bin/gaston", line 11, in <module>
    load_entry_point('gaston-py==0.1', 'console_scripts', 'gaston')()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
    return ep.load()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2343, in load
    return self.resolve()
  File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2349, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/gaston.py", line 5, in <module>
    import gaston_py.factory as factory
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/factory.py", line 7, in <module>
    import gaston_py.embedding as embedding
  File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/embedding.py", line 70
    yield from _create_embedding_list(graph, visited, neighbor_id)
             ^
SyntaxError: invalid syntax

in

yield from _create_embedding_list(graph, visited, neighbor_id)

Code block that produces the error:

def _create_embedding_list(graph, visited, node_id):
    for edge_label, neighbor_label, neighbor_id in sorted(_neighbor_labels(graph, visited, node_id)):
        if (node_id, neighbor_id) not in visited:
            visited.add((node_id, neighbor_id))
            visited.add((neighbor_id, node_id)) # if graph is undirected

            yield node_id, (edge_label, neighbor_label)
            yield from _create_embedding_list(graph, visited, neighbor_id)

Since this is the official implementation I suspect incompatibilities or similar. How do I get this code running? Thanks for any advice!

like image 907
Elias Avatar asked Jan 28 '23 04:01

Elias


1 Answers

As the traceback shows, you are running this code in Python 2.7. But yield from was introduced in Python 3 3 and is not supported on earlier versions.

like image 191
Daniel Roseman Avatar answered Jan 29 '23 18:01

Daniel Roseman