ImportError dependent on import order

Ouverte
#2,012 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python, tensorflow

Piste de recherche

Reproduisez l’installation de conda et de pip, puis exécutez les deux ordres d’importation présentés dans le rapport. Commencez dans tensorflow_probability/python/init.py au niveau de _validate_tf_environment et examinez pourquoi l’importation de tensorflow en premier rend tf_keras indisponible ; le travail est terminé lorsque l’installation documentée s’importe correctement dans les deux ordres.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Hi,

Working on an M3 macbook pro in macOS 15.6.

Using miniforge3.

Creating a conda env from scratch.

Running

conda install python pip ipython
pip install tensorflow tensorflow_probablity tensorflow-keras

to install python 3.13 and

tensorflow==2.20.0
tensorflow-probability==0.24.0
tensorflow_keras==0.1

then in a python terminal

In [1]: import tensorflow_probability
In [2]: import tensorflow

succeeds, and I can use tf and tf keras and import and use my own modules which use them . But

In [1]: import tensorflow
In [2]: import tensorflow_probability

returns the (familiar) error

File ~/miniforge3/envs/tensorflow/lib/python3.13/site-packages/tensorflow_probability/python/__init__.py:79, in _validate_tf_environment(package)
     77 if required_tensorflow_version[0] == '2':
     78   try:
---> 79     import tf_keras  # pylint: disable=unused-import
     80   except (ImportError, ModuleNotFoundError):
     81     # Print more informative error message, then reraise.
     82     print('\n\nFailed to import TF-Keras. Please note that TF-Keras is not '
     83           'installed by default when you install TensorFlow Probability. '
     84           'This is so that JAX-only users do not have to install TensorFlow '
   (...)     87           'This can be be done through installing the '
     88           'tensorflow-probability[tf] extra.\n\n')

ModuleNotFoundError: No module named 'tf_keras'

When importing tf and tfp at the top of my own modules, this error also appears when I import mymodule no matter what order the import of tf and tfp happens in the module file.

I am note even sure how to debug this! I guess something to do with namespaces getting messed up, but I am very much a user not a dev...

Langage dominant
Jupyter Notebook
Étoiles
4.4k
Forks
1.1k
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de tensorflow/probability

Toutes les issues de tensorflow/probability

Issues similaires

Plus d'issues Machine Learning

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.