7

I just want to import avro in python3. And I get error just import avro schema.

import os
import string
import sys

from avro import schema
...
# others are not matter

And I can only read

Traceback (most recent call last):
  File "/home/ktz/IdeaProjects/HadoopExample/src/main/python/chap4/writer_pairs.py", line 5, in <module>
    from avro import schema
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 896, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1139, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1115, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1096, in _legacy_get_spec
  File "<frozen importlib._bootstrap>", line 444, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 533, in spec_from_file_location
  File "/usr/local/lib/python3.5/dist-packages/avro-1.8.1-py3.5.egg/avro/schema.py", line 340
    except Exception, e:
                    ^
SyntaxError: invalid syntax

Sorry for that I`m first in Python..

5
  • Remove the comma in file and write as instead (so except Exception as e:) Jan 29, 2017 at 18:22
  • Possible duplicate of how to read avro files in python 3.5.2
    – ppasler
    Jan 29, 2017 at 18:25
  • See this: stackoverflow.com/questions/40732419/…
    – ppasler
    Jan 29, 2017 at 18:25
  • That's strange. It says "avro-1.8.1-py3.5.egg", which would seem to be targeted for Python 3.5, but the error message is pointing to Python 2-specific syntax. This might be a library bug. Jan 29, 2017 at 18:28
  • @ppasler Hm... maybe it could be.. but I`ll remain this for newbie in python just like me. Thanks! Jan 30, 2017 at 17:40

2 Answers 2

22

you need to use the package avro-python3 instead of avro if you're using Python3

1
6

You are using python2 version of avro code in python3. if you run the same using python2 then there won't be the error otherwise install python3 compatible avro.

3
  • You're right! Really I appreciate for your kindness.. It`s very helpful for me!! @Harry Jan 30, 2017 at 17:41
  • glad to be helpful.
    – Harry
    Jan 31, 2017 at 18:48
  • 1
    This is outdated now for folks using a up-to-date avro and Python 3.
    – kojiro
    Sep 28, 2020 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.