Forums

trying to install flair

I am using flair in my code and when I try to run it, it shows me this error:

ModuleNotFoundError: No module named 'flair'

When I try to install flair, it doesn't work. Someone please help. Thanks!

Could you tell us how the installation fails? Do you see any errors?

I managed to install it with a bash console but it's running a lot of errors right now. It could run locally so..

Error:

    2023-04-25 02:01:50.347365: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.
11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2023-04-25 02:01:50.347398: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set
 up on your machine.
/usr/local/lib/python3.10/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this ver
sion of SciPy (detected version 1.24.3
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Traceback (most recent call last):
  File "/home/jotan1/xx", line 12, in <module>
    classifier = TextClassifier.load('en-sentiment')
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/models/text_classification_model.py", line 137, in load
    return cast("TextClassifier", super().load(model_path=model_path))
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/nn/model.py", line 944, in load
    return cast("DefaultClassifier", super().load(model_path=model_path))
    return cast("DefaultClassifier", super().load(model_path=model_path))
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/nn/model.py", line 559, in load
    return cast("Classifier", super().load(model_path=model_path))
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/nn/model.py", line 191, in load
    state = load_torch_state(model_file)
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/file_utils.py", line 359, in load_torch_state
    return torch.load(f, map_location="cpu")
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

Okay, it works now! Had to uninstall everything, reinstall, then upgrape numphy package. Didn't have enough space on the drive as well so needed to upgrade that too.

Had another issue. Was running one of my commands and this error or

 File "/home/jotan1/xx", line 8, in <module>
    from flair.models import TextClassifier
  File "/home/jotan1/.local/lib/python3.10/site-packages/flair/__init__.py", line 5, in <module>
    import torch
  File "/usr/local/lib/python3.10/site-packages/torch/__init__.py", line 596, in <module>
    from ._tensor import Tensor
  File "/usr/local/lib/python3.10/site-packages/torch/_tensor.py", line 15, in <module>
    from torch.overrides import (
  File "/usr/local/lib/python3.10/site-packages/torch/overrides.py", line 1404, in <module>
    has_torch_function = _add_docstr(
RuntimeError: function '_has_torch_function' already has a docstring

Not sure why but when I try to uninstall torch and reinstall it, it runs this error -

ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/shutil.py", line 815, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/usr/local/bin/convert-caffe2-to-onnx' -> '/tmp/pip-uninstall-29v1d3qb/convert-caffe2-to-o
nnx'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 169, in exc_logging_wrapper
    status = run_func(*args)
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/commands/uninstall.py", line 105, in run
    uninstall_pathset = req.uninstall(
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/req/req_install.py", line 680, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/req/req_uninstall.py", line 381, in remove
    moved.stash(path)
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/req/req_uninstall.py", line 272, in stash
    renames(path, new_path)
  File "/home/jotan1/.local/lib/python3.10/site-packages/pip/_internal/utils/misc.py", line 313, in renames
    shutil.move(old, new)
  File "/usr/local/lib/python3.10/shutil.py", line 836, in move
    os.unlink(src)
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/convert-caffe2-to-onnx'

You can't pre-installed read-only uninstall torch, You can install different version in your home directory local files or create virtual environment.