Search code examples
pythonflair

Why do I get a TypeError while trying to import flair?


In the environment which I use as a kernel, 'TR-ML', flair=0.8 is installed which I confirm via conda list after activating the environment.

Only code I use is import flair

When I run the code, I get a very long error.

Here are the first few lines of the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-e42b806689dc> in <module>
----> 1 import flair

~/anaconda3/envs/tr-ml/lib/python3.8/site-packages/flair/__init__.py in <module>
      2 import torch
      3 from pathlib import Path
----> 4 from transformers import set_seed as hf_set_seed
      5 
      6 # global variable: cache_root

And here are the last few lines:

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

How to solve this?


Solution

  • https://stackoverflow.com/users/11502844/oivalf found the answer to this question. Downgrading 'protobuf' to 3.20 solved the problem.

    Here is the source I used for the downgrade operation: https://code.luasoftware.com/tutorials/python/python-pip-downgrade-package/