[Python] numpy TypeError with importing GPflow in ipython

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I installed GPflow and just tried to import it with ipython. But, I got an error like below.

    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    Cell In[2], line 1
    ----> 1 import gpflow

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/gpflow/__init__.py:17
    1 # Copyright 2016-2020 The GPflow Contributors. All Rights Reserved.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    (...) 14
    15 # flake8: noqa
    ---> 17 from . import (
    18 conditionals,
    19 config,
    20 covariances,
    21 expectations,
    22 experimental,
    23 functions,
    24 inducing_variables,
    25 kernels,
    26 kullback_leiblers,
    27 likelihoods,
    28 logdensities,
    29 mean_functions,
    30 models,
    31 monitor,
    32 optimizers,
    33 posteriors,
    34 probability_distributions,
    35 quadrature,
    36 utilities,
    37 )
    38 from .base import Module, Parameter
    39 from .config import default_float, default_int, default_jitter

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/gpflow/conditionals/__init__.py:1
    ----> 1 from . import conditionals, multioutput, sample_conditionals
    2 from .dispatch import conditional, sample_conditional
    3 from .uncertain_conditionals import uncertain_conditional

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/gpflow/conditionals/conditionals.py:17
    1 # Copyright 2017-2020 The GPflow Contributors. All Rights Reserved.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    (...) 12 # See the License for the specific language governing permissions and
    13 # limitations under the License.
    15 from typing import Optional
    ---> 17 import tensorflow as tf
    18 from check_shapes import check_shapes
    20 from ..base import MeanAndVariance

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/__init__.py:37
    34 import sys as _sys
    35 import typing as _typing
    ---> 37 from tensorflow.python.tools import module_util as _module_util
    38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
    40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/__init__.py:45
    43 from tensorflow.python import distribute
    44 # from tensorflow.python import keras
    ---> 45 from tensorflow.python.feature_column import feature_column_lib as feature_column
    46 # from tensorflow.python.layers import layers
    47 from tensorflow.python.module import module

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/feature_column/feature_column_lib.py:18
    15 """FeatureColumns: tools for ingesting and representing features."""
    17 # pylint: disable=unused-import,line-too-long,wildcard-import,g-bad-import-order
    ---> 18 from tensorflow.python.feature_column.feature_column import *
    19 from tensorflow.python.feature_column.feature_column_v2 import *
    20 from tensorflow.python.feature_column.sequence_feature_column import *

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/feature_column/feature_column.py:143
    141 from tensorflow.python.framework import sparse_tensor as sparse_tensor_lib
    142 from tensorflow.python.framework import tensor_shape
    --> 143 from tensorflow.python.layers import base
    144 from tensorflow.python.ops import array_ops
    145 from tensorflow.python.ops import check_ops

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/layers/base.py:16
    1 # Copyright 2015 The TensorFlow Authors. All Rights Reserved.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    (...) 13 # limitations under the License.
    14 # =============================================================================
    15 """Contains the base Layer class, from which all layers inherit."""
    ---> 16 from tensorflow.python.keras.legacy_tf_layers import base
    18 InputSpec = base.InputSpec
    20 keras_style_scope = base.keras_style_scope

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/keras/__init__.py:25
    22 from tensorflow.python.keras import distribute
    24 # See b/110718070#comment18 for more details about this import.
    ---> 25 from tensorflow.python.keras import models
    27 from tensorflow.python.keras.engine.input_layer import Input
    28 from tensorflow.python.keras.engine.sequential import Sequential

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/keras/models.py:22
    20 from tensorflow.python.keras import metrics as metrics_module
    21 from tensorflow.python.keras import optimizer_v1
    ---> 22 from tensorflow.python.keras.engine import functional
    23 from tensorflow.python.keras.engine import sequential
    24 from tensorflow.python.keras.engine import training

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/keras/engine/functional.py:32
    30 from tensorflow.python.keras.engine import input_spec
    31 from tensorflow.python.keras.engine import node as node_module
    ---> 32 from tensorflow.python.keras.engine import training as training_lib
    33 from tensorflow.python.keras.engine import training_utils
    34 from tensorflow.python.keras.saving.saved_model import network_serialization

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/keras/engine/training.py:54
    52 from tensorflow.python.keras.mixed_precision import loss_scale_optimizer as lso
    53 from tensorflow.python.keras.mixed_precision import policy
    ---> 54 from tensorflow.python.keras.saving import hdf5_format
    55 from tensorflow.python.keras.saving import save
    56 from tensorflow.python.keras.saving import saving_utils

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/tensorflow/python/keras/saving/hdf5_format.py:37
    35 # pylint: disable=g-import-not-at-top
    36 try:
    ---> 37 import h5py
    38 HDF5_OBJECT_HEADER_LIMIT = 64512
    39 except ImportError:

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/h5py/__init__.py:45
    36 _warn(("h5py is running against HDF5 {0} when it was built against {1}, "
    37 "this may cause problems").format(
    38 '{0}.{1}.{2}'.format(*version.hdf5_version_tuple),
    39 '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
    40 ))
    43 _errors.silence_errors()
    ---> 45 from ._conv import register_converters as _register_converters, \
    46 unregister_converters as _unregister_converters
    47 _register_converters()
    48 atexit.register(_unregister_converters)

    File h5py/_conv.pyx:1, in init h5py._conv()

    File h5py/h5r.pyx:1, in init h5py.h5r()

    File h5py/h5p.pyx:1, in init h5py.h5p()

    File h5py/h5t.pyx:300, in init h5py.h5t()

    File h5py/h5t.pyx:295, in h5py.h5t._get_available_ftypes()

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/numpy/core/getlimits.py:504, in finfo.__new__(cls, dtype)
    502 if obj is not None:
    503 return obj
    --> 504 obj = object.__new__(cls)._init(dtype)
    505 for dt in dtypes:
    506 cls._finfo_cache[dt] = obj

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/numpy/core/getlimits.py:532, in finfo._init(self, dtype)
    530 self._str_resolution = machar._str_resolution.strip()
    531 self._str_smallest_normal = machar._str_smallest_normal.strip()
    --> 532 self._str_smallest_subnormal = machar._str_smallest_subnormal.strip()
    533 return self

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/numpy/core/getlimits.py:89, in MachArLike._str_smallest_subnormal(self)
    86 @property
    87 def _str_smallest_subnormal(self):
    88 """Return the string representation of the smallest subnormal."""
    ---> 89 return self._float_to_str(self.smallest_subnormal)

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/numpy/core/getlimits.py:119, in MachArLike._float_to_str(self, value)
    111 def _float_to_str(self, value):
    112 """Converts float to str.
    113
    114 Parameters
    (...) 117 value to be converted.
    118 """
    --> 119 return self.params['fmt'] % array(_fr0(value)[0], self.ftype)

    File ~/miniconda3/envs/gpr/lib/python3.11/site-packages/numpy/core/arrayprint.py:1575, in _array_str_implementation(a, max_line_width, precision, suppress_small, array2string)
    1571 def _array_str_implementation(
    1572 a, max_line_width=None, precision=None, suppress_small=None,
    1573 array2string=array2string):
    1574 """Internal version of array_str() that allows overriding array2string."""
    -> 1575 if (_format_options['legacy'] <= 113 and
    1576 a.shape == () and not a.dtype.names):
    1577 return str(a.item())
    1579 # the str of 0d arrays is a special case: It should appear like a scalar,
    1580 # so floats are not truncated by `precision`, and strings are not wrapped
    1581 # in quotes. So we return the str of the scalar value.

    TypeError: '<=' not supported between instances of 'str' and 'int'


    The versions of the modules are as follows.
    numpy version: 1.24.3
    GPflow version: 2.10.0
    python version: 3.11.5
    ipython version: 9.4.0

    One thing weird about this error is that this error actually disappear if I don't use ipython. If I use just normal python (this means that type "python" in terminal instead of "ipython" to launch Python) and do import gpflow, then it works without the numpy TypeError above. But, I feel much comfortable with ipython platform for using Python and thus I hope to use gpflow in ipython.

    So, may I ask you how I could solve this issue?

    Continue reading...

Compartilhe esta Página