libtorchtext.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs TorchText Error Fixed

The error:

OSError: /usr/local/lib/python3.11/dist-packages/torchtext/lib/libtorchtext.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs

suggests that there is a compatibility issue between torchtext and torch. This happens when torchtext is built against a different version of torch than the one currently installed.

Solution: Upgrade/Downgrade PyTorch and TorchText

  1. Check the Installed Versions
    Run the following command to check your PyTorch and TorchText versions: python -c "import torch; import torchtext; print(torch.__version__, torchtext.__version__)"
  2. Uninstall Existing Packages
    First, remove PyTorch and TorchText: pip uninstall torch torchtext -y
  3. Reinstall Compatible Versions
    If you are using PyTorch 2.x, reinstall using: pip install torch torchvision torchaudio torchtext --index-url https://download.pytorch.org/whl/cpu (Replace cpu with cu118 for CUDA 11.8, or cu121 for CUDA 12.1 if you have a GPU.)
  4. Verify Installation
    Run the following to check if the error persists: import torch import torchtext print(torch.__version__, torchtext.__version__)

Alternative: Use Matching Versions

If the problem persists, you may need to install specific compatible versions. For example, if you are using PyTorch 2.1.0, install TorchText 0.16.0:

pip install torch==2.1.0 torchtext==0.16.0


Discover more from Science Comics

Subscribe to get the latest posts sent to your email.

Leave a Reply

error: Content is protected !!