Home > Net >  Run time error and import error for Tensorflow and keras packages
Run time error and import error for Tensorflow and keras packages

Time:08-12

I use miniconda3 installer in the linux aarch64 architecture (Linux version 4.9.277-122 (root@builder_n2) (gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-6ubuntu2) ) #1 SMP PREEMPT ) to create virtual environment in linux. I install the following packages without having any issue.

Package                      Version
---------------------------- ------------
absl-py                      1.2.0
appdirs                      1.4.4
astunparse                   1.6.3
attrs                        22.1.0
audioread                    2.1.9
cachetools                   5.2.0
certifi                      2022.6.15
cffi                         1.15.1
charset-normalizer           2.1.0
cycler                       0.11.0
decorator                    5.1.1
distlib                      0.3.5
filelock                     3.8.0
flatbuffers                  2.0
fonttools                    4.34.4
fpdf                         1.7.2
gast                         0.4.0
google-auth                  2.10.0
google-auth-oauthlib         0.4.6
google-pasta                 0.2.0
grpcio                       1.47.0
h5py                         3.7.0
idna                         3.3
joblib                       1.1.0
jsonschema                   4.9.1
keras                        2.9.0
Keras-Preprocessing          1.1.2
kiwisolver                   1.4.4
kneed                        0.8.1
libclang                     14.0.6
librosa                      0.9.2
llvmlite                     0.39.0
logger                       1.4
Markdown                     3.4.1
MarkupSafe                   2.1.1
matplotlib                   3.5.3
numba                        0.56.0
numpy                        1.22.4
oauthlib                     3.2.0
opt-einsum                   3.3.0
packaging                    21.3
pandas                       1.4.3
pickle5                      0.0.11
Pillow                       9.2.0
pip                          22.2.2
platformdirs                 2.5.2
pooch                        1.6.0
protobuf                     3.19.4
pyasn1                       0.4.8
pyasn1-modules               0.2.8
pycparser                    2.21
pyparsing                    3.0.9
pyrsistent                   0.18.1
python-dateutil              2.8.2
python-Levenshtein           0.12.2
pytz                         2022.1
rdp                          0.8
requests                     2.28.1
requests-oauthlib            1.3.1
resampy                      0.4.0
rsa                          4.9
scikit-learn                 1.1.2
scipy                        1.9.0
seaborn                      0.11.2
setuptools                   63.4.3
six                          1.16.0
SoundFile                    0.10.3.post1
tensorboard                  2.9.1
tensorboard-data-server      0.6.1
tensorboard-plugin-wit       1.8.1
tensorflow                   2.10.0rc0
tensorflow-cpu-aws           2.10.0rc0
tensorflow-estimator         2.9.0
tensorflow-io-gcs-filesystem 0.26.0
termcolor                    1.1.0
threadpoolctl                3.1.0
typing_extensions            4.3.0
urllib3                      1.26.11
virtualenv                   20.16.3
watchdog                     2.1.9
Werkzeug                     2.2.2
wheel                        0.37.1
wrapt                        1.14.1

However when I import all those packages in the python, tensorflow and keras give the following error. May I know how can I solve this issue?

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/keras/__init__.py", line 21, in <module>
    from tensorflow.python import tf2
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 42, in <module>
    from tensorflow.python import data
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/__init__.py", line 21, in <module>
    from tensorflow.python.data import experimental
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 419, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/data_service_ops.py", line 24, in <module>
    from tensorflow.python.data.experimental.ops import compression_ops
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 16, in <module>
    from tensorflow.python.data.util import structure
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/util/structure.py", line 23, in <module>
    from tensorflow.python.data.util import nest
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/util/nest.py", line 36, in <module>
    from tensorflow.python.framework import sparse_tensor as _sparse_tensor
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/sparse_tensor.py", line 24, in <module>
    from tensorflow.python.framework import constant_op
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/constant_op.py", line 25, in <module>
    from tensorflow.python.eager import execute
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/eager/execute.py", line 23, in <module>
    from tensorflow.python.framework import dtypes
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py", line 34, in <module>
    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
TypeError: Unable to convert function return value to a Python type! The signature was
        () -> handle
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 42, in <module>
    from tensorflow.python import data
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/__init__.py", line 21, in <module>
    from tensorflow.python.data import experimental
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 419, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/data_service_ops.py", line 24, in <module>
    from tensorflow.python.data.experimental.ops import compression_ops
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 16, in <module>
    from tensorflow.python.data.util import structure
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/util/structure.py", line 23, in <module>
    from tensorflow.python.data.util import nest
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/data/util/nest.py", line 36, in <module>
    from tensorflow.python.framework import sparse_tensor as _sparse_tensor
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/sparse_tensor.py", line 24, in <module>
    from tensorflow.python.framework import constant_op
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/constant_op.py", line 25, in <module>
    from tensorflow.python.eager import execute
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/eager/execute.py", line 23, in <module>
    from tensorflow.python.framework import dtypes
  File "/home/su/miniconda3/envs/penvreq/lib/python3.10/site-packages/tensorflow/python/framework/dtypes.py", line 34, in <module>
    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
TypeError: Unable to convert function return value to a Python type! The signature was
        () -> handle

I also search in stackoverflow other questions and found RuntimeError: module compiled against API version a but this version of numpy is 9 But in here the solution is to update the numpy. My case is I cannot update the numpy to the latest version (1.23.1) because the dependency of the numpy in the librosa is <1.23.0. May I know how can I solve this error in tensorflow and keras? Is it related to numpy version incompatible with the tensorflow version? But when I install the tensorflow using pip in the miniconda3's virtual environment, it require numpy>=1.20 version and I installed numpy 1.22.4.

Moreover, I cannot install tensorflow with conda install command because whenever I install tensorflow with conda, it said that

PackagesNotFoundError: The following packages are not available from current channels:

  - tensorflow

Current channels:

  - https://conda.anaconda.org/conda-forge/linux-aarch64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://conda.anaconda.org/default/linux-aarch64
  - https://conda.anaconda.org/default/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

Therefore, I use pip to install all those packages. Moreover, when I search conda search tensorflow, it said

Loading channels: done
No match found for: tensorflow.

I also would like to know which channel should I define to be able to install with conda ? Right now I define conda-forge and default as a channel.

CodePudding user response:

Not sure if this can solve all your other issues. But if you want to install Tensorflow through conda, what I like to do is to install it at the moment of the environment creation, like this:

conda create -n my_env tensorflow-gpu=my_version

Or

conda create -n my_env tensorflow

Creates the environment with the latest version of Tensorflow for CPU.

After that you can install all your other packages and see if the issue is resolved. Hope this helps.

CodePudding user response:

Moreover when I did conda search for tensorflow in the base of miniconda in Linux aarch64, conda search tensorflow

I got the below error

 /home/su/miniconda3/bin/conda search tensorflow`

  environment variables:
                 CIO_TEST=<not set>
        CONDA_DEFAULT_ENV=base
                CONDA_EXE=/home/su/miniconda3/bin/conda
             CONDA_PREFIX=/home/su/miniconda3
    CONDA_PROMPT_MODIFIER=(base)
         CONDA_PYTHON_EXE=/home/su/miniconda3/bin/python
               CONDA_ROOT=/home/su/miniconda3
              CONDA_SHLVL=1
           CURL_CA_BUNDLE=<not set>
                     PATH=/home/su/miniconda3/bin:/home/su/.local/bin:/home/su/minic
                          onda3/bin:/home/su/miniconda3/condabin:/usr/local/sbin:/usr/local/
                          bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bi
                          n
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>
         UBUNTU_MENUPROXY=<set>
               http_proxy=<set>
              https_proxy=<set>
                 no_proxy=<set>

     active environment : base
    active env location : /home/su/miniconda3
            shell level : 1
       user config file : /home/su/.condarc
 populated config files : /home/su/.condarc
          conda version : 4.9.2
    conda-build version : not installed
         python version : 3.9.1.final.0
       virtual packages : __glibc=2.31=0
                          __unix=0=0
                          __archspec=1=aarch64
       base environment : /home/su/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/default/linux-aarch64
                          https://conda.anaconda.org/default/noarch
                          https://conda.anaconda.org/conda-forge/linux-aarch64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/su/miniconda3/pkgs
                          /home/su/.conda/pkgs
       envs directories : /home/su/miniconda3/envs
                          /home/su/.conda/envs
               platform : linux-aarch64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.1 Linux/4.9.277-122 ubuntu/20.04.4 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.

If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?

Not sure why miniconda give this issue. Is it related to .condarc file?

  • Related