Search code examples
pythonpython-3.xpykml

Syntax error when importing pykml.factory


So I am trying to use pyKML to create a KML file for google earth however when I try and import the module, I get the following:

 from pykml.factory import KML_ElementMaker as KML
Traceback (most recent call last):

  File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-69-cdeb04502fb8>", line 1, in <module>
    from pykml.factory import KML_ElementMaker as KML

  File "C:\Anaconda\lib\site-packages\pykml\factory.py", line 216
    print write_python_script_for_kml_document(doc)
                                             ^
SyntaxError: invalid syntax

I tried to use simpleKML but it is not available for python 3.6


Solution

  • print write_python_script_for_kml_document(doc)
    

    is a line of code which works in Python 2, but doesn't in Python 3. As Python 3 requires parentheses:

    print(write_python_script_for_kml_document(doc))
    

    So I guess the library you are trying to use hasn't been adapted to Python 3. Or at least this version hasn't.