Rasa: ImportError: cannot import name 'ClassVar' with Python 3

Created on 26 Jul 2017  路  6Comments  路  Source: RasaHQ/rasa

I got an import error, and did not find any issue addressing it. The error is due to the typing module.The Python 3 version of the module doesn't have the ClassVar class, but the Python 2 version does.

Here is the error I get:

$ python3 -m rasa_nlu.server
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/amechouc/Documents/rasa_nlu/rasa_nlu/rasa_nlu/server.py", line 18, in <module>
    from rasa_nlu.data_router import DataRouter, InvalidModelError
  File "/home/amechouc/Documents/rasa_nlu/rasa_nlu/rasa_nlu/data_router.py", line 18, in <module>
    from rasa_nlu.components import ComponentBuilder
  File "/home/amechouc/Documents/rasa_nlu/rasa_nlu/rasa_nlu/components.py", line 15, in <module>
    from typing import ClassVar
ImportError: cannot import name 'ClassVar'

It works fine with Python 2. Does anyone encounter the same error?


rasa NLU version : 0.10.0a0

Operating system : Linux

Python version: 3.5.2

type

All 6 comments

I see it, can tell it was added during this commit https://github.com/RasaHQ/rasa_nlu/commit/e3740fa25f12f30b5ed38204740bc11d0070ab50 but I can't see where it is actually used.

Also strange is that the CI tests for 3.5 are passing fine.

@tmbo?

At the moments as it looks like type annotations are not used that much in the code, ClassVar is only used as an import. But as it is a "recent" addition (PEP 526) you may just need to update your typing version. Which version do you have?
By the way, the typing package in Python 2 is a backport as it was introduced with Python 3

Was just going to ask how @FlorentF9 installed typing and what version they had. Beat me to it @PHLF !

I tried installing with both methods, from the repo and with pip. So I tried with typing version 3.5.3.0 (as specified in the requirements file) and with version 3.6.1 (latest version available with pip).

@FlorentF9 I have removed that unnecessary import in the latest master. can you try again after installing from github? I agree with PHLF, its typing package version problem.

Now it seems to work! Thanks!

Was this page helpful?
0 / 5 - 0 ratings