ImportError ... Failed to load the native TensorFlow runtime

My app appears to boot up fine until it gets to import tensorflow.compat.v2 as tf.

Here is the full traceback:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py", line 379, in _run_script
    exec(code, module.__dict__)
  File "/app/msvc/msvc/src/app.py", line 158, in <module>
    main()
  File "/app/msvc/msvc/src/app.py", line 105, in main
    frill_module = load_frill_module()
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/caching/cache_utils.py", line 145, in wrapper
    return get_or_create_cached_value()
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/caching/cache_utils.py", line 137, in get_or_create_cached_value
    return_value = func(*args, **kwargs)
  File "/app/msvc/msvc/src/features/load_frill_module.py", line 11, in load_frill_module
    import tensorflow.compat.v2 as tf
  File "/home/appuser/venv/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/appuser/venv/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 40, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "/home/appuser/venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/caching/cache_utils.py", line 126, in get_or_create_cached_value
    return_value = cache.read_value(value_key)
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/caching/singleton_decorator.py", line 263, in read_value
    raise CacheKeyNotFoundError()
streamlit.caching.cache_errors.CacheKeyNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /home/appuser/venv/lib/python3.8/site-packages/tensorflow/python/../../../../libgrpc.so.20)


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

Here are the contents of my environment.yml file:

name: msvc_env_mm
channels:
  - conda-forge
  - pytorch-nightly
  - defaults
dependencies:
  - _libgcc_mutex=0.1
  - _openmp_mutex=4.5
  - abseil-cpp=20210324.2
  - absl-py=0.15.0
  - aiohttp=3.8.1
  - aiosignal=1.2.0
  - alsa-lib=1.2.3
  - altair=4.2.0
  - appdirs=1.4.4
  - argh=0.26.2
  - argon2-cffi=21.3.0
  - argon2-cffi-bindings=21.2.0
  - arrow-cpp=5.0.0
  - astor=0.8.1
  - asttokens=2.0.5
  - astunparse=1.6.3
  - async-timeout=4.0.2
  - attrs=21.4.0
  - av=8.0.2
  - aws-c-auth=0.6.8
  - aws-c-cal=0.5.12
  - aws-c-common=0.6.17
  - aws-c-compression=0.2.14
  - aws-c-event-stream=0.2.7
  - aws-c-http=0.6.10
  - aws-c-io=0.10.14
  - aws-c-mqtt=0.7.10
  - aws-c-s3=0.1.29
  - aws-c-sdkutils=0.1.1
  - aws-checksums=0.1.12
  - aws-crt-cpp=0.17.10
  - aws-sdk-cpp=1.9.160
  - backcall=0.2.0
  - backports=1.0
  - backports.functools_lru_cache=1.6.4
  - backports.zoneinfo=0.2.1
  - base58=2.1.1
  - black=21.5b2
  - blas=1.0
  - bleach=4.1.0
  - blinker=1.4
  - bokeh=2.3.3
  - boto3=1.20.41
  - botocore=1.23.41
  - bottleneck=1.3.2
  - brotli=1.0.9
  - brotli-bin=1.0.9
  - brotlipy=0.7.0
  - bzip2=1.0.8
  - c-ares=1.18.1
  - ca-certificates=2021.10.8
  - cached-property=1.5.2
  - cached_property=1.5.2
  - cachetools=4.2.4
  - certifi=2021.10.8
  - cffi=1.15.0
  - charset-normalizer=2.0.10
  - click=8.0.3
  - cloudpickle=2.0.0
  - colorama=0.4.4
  - cryptography=36.0.1
  - cudatoolkit=11.5.0
  - cudnn=8.2.1.32
  - cycler=0.11.0
  - cytoolz=0.11.2
  - daal4py=2021.4.0
  - dal=2021.4.0
  - dask=2022.1.0
  - dask-core=2022.1.0
  - dataclasses=0.8
  - dbus=1.13.6
  - debugpy=1.5.1
  - decorator=5.1.1
  - defusedxml=0.7.1
  - distributed=2022.1.0
  - entrypoints=0.3
  - executing=0.8.2
  - expat=2.4.3
  - ffmpeg=4.2.3
  - ffmpeg-python
  - flit-core=3.6.0
  - font-ttf-dejavu-sans-mono=2.37
  - font-ttf-inconsolata=3.000
  - font-ttf-source-code-pro=2.038
  - font-ttf-ubuntu=0.83
  - fontconfig=2.13.1
  - fonts-conda-ecosystem=1
  - fonts-conda-forge=1
  - fonttools=4.28.5
  - freetype=2.10.4
  - frozenlist=1.2.0
  - fsspec=2022.1.0
  - gast=0.4.0
  - gettext=0.19.8.1
  - gflags=2.2.2
  - giflib=5.2.1
  - gitdb=4.0.9
  - gitpython=3.1.26
  - glog=0.5.0
  - gmp=6.2.1
  - gnutls=3.6.13
  - google-auth=1.35.0
  - google-auth-oauthlib=0.4.6
  - google-pasta=0.2.0
  - grpc-cpp=1.42.0
  - grpcio=1.42.0
  - gst-plugins-base=1.18.5
  - gstreamer=1.18.5
  - h5py=3.1.0
  - hdf5=1.10.6
  - heapdict=1.0.1
  - icu=69.1
  - idna=3.3
  - importlib-metadata=4.10.1
  - importlib_resources=5.4.0
  - intel-openmp=2022.0.1
  - ipykernel=6.7.0
  - ipython=8.0.1
  - ipython_genutils=0.2.0
  - ipywidgets=7.6.5
  - jbig=2.1
  - jedi=0.18.1
  - jinja2=3.0.3
  - jmespath=0.10.0
  - joblib=1.1.0
  - jpeg=9d
  - jsonschema=4.4.0
  - jupyter_client=7.1.2
  - jupyter_core=4.9.1
  - jupyterlab_pygments=0.1.2
  - jupyterlab_widgets=1.0.2
  - keras=2.6.0
  - keras-preprocessing=1.1.2
  - kiwisolver=1.3.2
  - krb5=1.19.2
  - lame=3.100
  - lcms2=2.12
  - ld_impl_linux-64=2.36.1
  - lerc=3.0
  - libblas=3.9.0
  - libbrotlicommon=1.0.9
  - libbrotlidec=1.0.9
  - libbrotlienc=1.0.9
  - libcblas=3.9.0
  - libclang=13.0.0
  - libcurl=7.81.0
  - libdeflate=1.8
  - libedit=3.1.20191231
  - libev=4.33
  - libevent=2.1.10
  - libffi=3.4.2
  - libflac=1.3.3
  - libgcc-ng=11.2.0
  - libgfortran-ng=11.2.0
  - libgfortran5=11.2.0
  - libglib=2.70.2
  - libgomp=11.2.0
  - libiconv=1.16
  - liblapack=3.9.0
  - libllvm13=13.0.0
  - libnghttp2=1.43.0
  - libnsl=2.0.0
  - libogg=1.3.4
  - libopus=1.3.1
  - libpng=1.6.37
  - libpq=14.1
  - libprotobuf=3.18.1
  - libsndfile=1.0.31
  - libsodium=1.0.18
  - libssh2=1.10.0
  - libstdcxx-ng=11.2.0
  - libthrift=0.15.0
  - libtiff=4.3.0
  - libutf8proc=2.7.0
  - libuuid=2.32.1
  - libuv=1.43.0
  - libvorbis=1.3.7
  - libwebp-base=1.2.2
  - libxcb=1.13
  - libxkbcommon=1.0.3
  - libxml2=2.9.12
  - libzlib=1.2.11
  - locket=0.2.0
  - lz4-c=1.9.3
  - markdown=3.3.6
  - markupsafe=2.0.1
  - matplotlib=3.5.1
  - matplotlib-base=3.5.1
  - matplotlib-inline=0.1.3
  - mistune=0.8.4
  - mkl=2022.0.1
  - modin=0.12.1
  - modin-core=0.12.1
  - modin-dask=0.12.1
  - mpi=1.0
  - mpich=3.4.3
  - msgpack-python=1.0.3
  - multidict=5.2.0
  - munkres=1.1.4
  - mypy_extensions=0.4.3
  - mysql-common=8.0.28
  - mysql-libs=8.0.28
  - nbclient=0.5.10
  - nbconvert=6.4.0
  - nbformat=5.1.3
  - nccl=2.11.4.1
  - ncurses=6.3
  - nest-asyncio=1.5.4
  - nettle=3.6
  - notebook=6.4.7
  - nspr=4.32
  - nss=3.74
  - numexpr=2.7.3
  - numpy=1.19.5
  - oauthlib=3.1.1
  - olefile=0.46
  - openh264=2.1.1
  - openjpeg=2.4.0
  - openssl=1.1.1l
  - opt_einsum=3.3.0
  - orc=1.7.1
  - packaging=21.3
  - pandas=1.3.5
  - pandoc=2.17.0.1
  - pandocfilters=1.5.0
  - parquet-cpp=1.5.1
  - parso=0.8.3
  - partd=1.2.0
  - pathspec=0.9.0
  - patsy=0.5.2
  - pcre=8.45
  - pexpect=4.8.0
  - pickleshare=0.7.5
  - pillow=8.4.0
  - pip=21.3.1
  - prometheus_client=0.12.0
  - prompt-toolkit=3.0.24
  - protobuf=3.18.1
  - psutil=5.9.0
  - pthread-stubs=0.4
  - ptyprocess=0.7.0
  - pure_eval=0.2.2
  - pyarrow=5.0.0
  - pyasn1=0.4.8
  - pyasn1-modules=0.2.7
  - pycparser=2.21
  - pydeck=0.5.0
  - pydub=0.25.1
  - pygments=2.11.2
  - pyjwt=2.3.0
  - pympler=0.9
  - pyopenssl=21.0.0
  - pyparsing=3.0.7
  - pyqt=5.12.3
  - pyqt-impl=5.12.3
  - pyqt5-sip=4.19.18
  - pyqtchart=5.12
  - pyqtwebengine=5.12.1
  - pyrsistent=0.18.1
  - pysocks=1.7.1
  - pysoundfile=0.10.3.post1
  - python=3.8.12
  - python-dateutil=2.8.2
  - python-flatbuffers=1.12
  - python-tzdata=2021.5
  - python_abi=3.8
  - pytorch=1.11.0.*
  - pytorch-mutex=1.0
  - pytz=2021.3
  - pytz-deprecation-shim=0.1.0.post0
  - pyu2f=0.1.5
  - pyyaml=6.0
  - pyzmq=22.3.0
  - qt=5.12.9
  - re2=2021.11.01
  - readline=8.1
  - regex=2022.1.18
  - requests=2.27.1
  - requests-oauthlib=1.3.0
  - rsa=4.8
  - s2n=1.3.0
  - s3transfer=0.5.0
  - scikit-learn=1.0.2
  - scikit-learn-intelex=2021.4.0
  - scipy=1.7.3
  - seaborn=0.11.2
  - seaborn-base=0.11.2
  - send2trash=1.8.0
  - setuptools=59.8.0
  - six=1.15.0
  - smmap=3.0.5
  - snappy=1.1.8
  - sortedcontainers=2.4.0
  - sqlite=3.37.0
  - stack_data=0.1.4
  - statsmodels=0.13.1
  - streamlit=1.4.0
  - swifter=1.0.9
  - tbb=2021.5.0
  - tblib=1.7.0
  - tensorboard=2.6.0
  - tensorboard-data-server=0.6.0
  - tensorboard-plugin-wit=1.8.1
  - tensorflow=2.6.2
  - tensorflow-base=2.6.2
  - tensorflow-estimator=2.6.2
  - tensorflow-hub=0.12.0
  - termcolor=1.1.0
  - terminado=0.12.1
  - testpath=0.5.0
  - threadpoolctl=3.0.0
  - tk=8.6.11
  - toml=0.10.2
  - tomli=2.0.0
  - toolz=0.11.2
  - torchaudio=0.11.0.*
  - tornado=6.1
  - tqdm=4.62.3
  - traitlets=5.1.1
  - typed-ast=1.5.1
  - typing-extensions=3.7.4.3
  - typing_extensions=3.7.4.3
  - tzdata=2021e
  - tzlocal=4.1
  - unicodedata2=14.0.0
  - urllib3=1.26.8
  - validators=0.18.2
  - watchdog=2.1.6
  - wcwidth=0.2.5
  - webencodings=0.5.1
  - werkzeug=2.0.2
  - wheel=0.37.1
  - widgetsnbextension=3.5.2
  - wrapt=1.12.1
  - x264=1!152.20180806
  - xorg-libxau=1.0.9
  - xorg-libxdmcp=1.1.3
  - xz=5.2.5
  - yaml=0.2.5
  - yarl=1.7.2
  - zeromq=4.3.4
  - zict=2.0.0
  - zipp=3.7.0
  - zlib=1.2.11
  - zstd=1.5.2
  - pip:
    - streamlit-webrtc>=0.34.2
    - -e .

Here is the repo link: GitHub - michen00/MSVC: multilingual speech valence classifier

I have tried changing tensorflow, tensorflow-base, and tensorflow-estimator to versions 2.3.0, 2.6.0, and 2.7.0 as well as including tensorflow in packages.txt, but the build does not get past creating the environment when I do this.

Here is the offending code in context:

@st.experimental_singleton
def load_frill_module():
    """returns the FRILL module as a tensorflow _UserObject"""
    with st.spinner("thank you for your patience..."):
        import tensorflow.compat.v2 as tf
        import tensorflow_hub as hub

        tf.enable_v2_behavior()
        frill_path = "msvc/src/features/FRILL"
        return hub.load(frill_path)

I have also tried the following variant of the method, which results in the same error:

@st.experimental_singleton
def load_frill_module():
    """returns the FRILL module as a tensorflow _UserObject"""
    with st.spinner("thank you for your patience..."):
        # import tensorflow.compat.v2 as tf
        import tensorflow as tf
        import tensorflow_hub as hub

        # tf.enable_v2_behavior()
        frill_path = "msvc/src/features/FRILL"
        return hub.load(frill_path)

What should I do to resolve this? Am I specifying my environment incorrectly? Is there an incompatibility between packages I am not aware of? Please advise. :pray:

UPDATE: I wasn’t able to figure this out, but I worked around it by using pip list --format=freeze > requirements.txt from within the environment and then manually editing some remaining incompatibilities.