apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.41k stars 636 forks source link

ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found #1759

Closed robthemonster closed 1 year ago

robthemonster commented 1 year ago

🐞Describing the bug

While I am able to import and use coremltools==4.1 in my environment, version 6.1 give me this error instead.

ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /export/apps/python/3.7/lib/python3.7/site-packages/coremltools/libmilstoragepython.so)

Stack Trace

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_717/1370749834.py in <module>
      2 import pandas as pd
      3 import xgboost
----> 4 import coremltools
      5 import numpy as np
      6 import json

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/__init__.py in <module>
     89 
     90 # expose sub packages as directories
---> 91 from . import converters
     92 from . import proto
     93 from . import models

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/__init__.py in <module>
      5 
      6 # expose directories as imports
----> 7 from . import libsvm
      8 from . import sklearn
      9 from . import xgboost

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/libsvm/__init__.py in <module>
      6 
      7 from ..._deps import _HAS_LIBSVM
----> 8 from . import _libsvm_converter, _libsvm_util
      9 
     10 if _HAS_LIBSVM:

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/libsvm/_libsvm_converter.py in <module>
      5 
      6 from coremltools import __version__ as ct_version
----> 7 from coremltools.models import _METADATA_SOURCE, _METADATA_VERSION
      8 
      9 from ... import SPECIFICATION_VERSION

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/models/__init__.py in <module>
     35 
     36 from . import neural_network
---> 37 from . import ml_program

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/models/ml_program/__init__.py in <module>
      4 # found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
      5 
----> 6 from . import compression_utils

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/models/ml_program/compression_utils.py in <module>
      7 from coremltools.converters.mil import Operation as _Operation
      8 from coremltools.converters.mil.converter import mil_convert as _mil_convert
----> 9 from coremltools.converters.mil.frontend.milproto.load import \
     10     load as _milproto_to_pymil
     11 from coremltools.converters.mil.mil.passes.compression_passes import \

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/mil/frontend/milproto/__init__.py in <module>
      4 # found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
      5 
----> 6 from .load import load

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/mil/frontend/milproto/load.py in <module>
     19 from coremltools.converters.mil.mil.ops.registry import \
     20     SSAOpRegistry as _SSAOpRegistry
---> 21 from coremltools.libmilstoragepython import _BlobStorageReader as BlobReader
     22 from coremltools.proto import MIL_pb2 as pm
     23 from coremltools.proto import Model_pb2 as ml

ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /export/apps/python/3.7/lib/python3.7/site-packages/coremltools/libmilstoragepython.so)

To Reproduce

import coremltools

System environment (please complete the following information):

Additional context

I am working in a fixed environment, so I'm not able to change the version of CXXABI on my host. This issue blocks me from upgrading to any version of coremltools newer than 4.1; Since 4.1 only supports Python <=3.7, this also blocks our upgrade to a newer version of Python. Based on manual testing, every major release after 4.1 is incompatible.

Is this new CXXABI dependency (moving from 4.1 to 5.x) expected? Is there a way to produce a compatible wheel?

TobyRoseman commented 1 year ago

I believe this is caused because we require C++17.

As a workaround for being in a fixed environment, try installing coremltools (just coremltools not its dependencies) from source rather than doing a binary installation.

From a fresh environment, run: pip install --no-binary coremltools coremltools

Installing this way means you will not have libmilstoragepython.so. So you should not received the above error. However it also means you will have limited coremltools functionality. I believe this mainly means you will not be able to save or load mlpackages. I think mlmodels should still work fine. It's also important that you use the most recent version of coremltools (6.2) or you will receive an error when trying to import coremltools.

@robthemonster - Let us know if this works for your use case. Or if you have any questions.

robthemonster commented 1 year ago

Thanks for the workaround; It sounds great for my use case. However, it seems I get a different error when I try this:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_179/2568829930.py in <module>
     13 coreml_model = coremltools.converters.xgboost.convert(xgb_model,
     14                                                       mode="classifier",
---> 15                                                       n_classes=2)
     16 

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/xgboost/_tree.py in convert(model, feature_names, target, force_32bit_float, mode, class_labels, n_classes)
     80             mode=mode,
     81             class_labels=class_labels,
---> 82             n_classes=n_classes,
     83         )
     84     )

/export/apps/python/3.7/lib/python3.7/site-packages/coremltools/converters/xgboost/_tree_ensemble.py in convert_tree_ensemble(model, feature_names, target, force_32bit_float, mode, class_labels, n_classes)
    150     """
    151     if not (_HAS_XGBOOST):
--> 152         raise RuntimeError("xgboost not found. xgboost conversion API is disabled.")
    153     accepted_modes = ["regressor", "classifier"]
    154     if mode not in accepted_modes:

RuntimeError: xgboost not found. xgboost conversion API is disabled.

I do have xgboost installed via pip and coremltools==4.1 was able to detect it (when installed via wheel). Do you think the --no-binary flag causes coremltools to be unable to find it? edit: This seems to have been an issue with my workspace, I got it working with your suggestion. Thanks for your help (and for enabling this with 6.2)!