Cannot import name 'network' from 'tensorflow.python.keras.engine' - python-3.x

When trying to load BERT QA I get the following ImportError:
"Cannot import name 'network' from 'tensorflow.python.keras.engine'"
The full error log follows below
Following this post,
ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine'
I have tried the following steps,
pip uninstall tf-agents
pip install tf-agents-nightly
and then in Python,
from tf_agents.environments import suite_gym
However, this did not resolve the problem. Any suggestions would be very welcome!
In case it is helpful, I'm running TensorFlow version 2.3.0. Also, the script init.py referred to below does exist, however the file is empty, i.e. 0 bytes.
ImportError Traceback (most recent call last)
<ipython-input-2-323bac0cb5ba> in <module>
----> 1 from bert_qa import squad
~/anaconda3/lib/python3.8/site-packages/bert_qa/squad.py in <module>
34 from . import model_training_utils
35 from . import bert_modeling as modeling
---> 36 from . import bert_models
37 from . import optimization
38 from . import input_pipeline
~/anaconda3/lib/python3.8/site-packages/bert_qa/bert_models.py in <module>
25 from . import bert_modeling
26 from . import weighted_sparse_categorical_crossentropy
---> 27 from . transformer_encoder import TransformerEncoder
28 from . albert_transformer_encoder import AlbertTransformerEncoder
29 from . import bert_classifier
~/anaconda3/lib/python3.8/site-packages/bert_qa/transformer_encoder.py in <module>
22 import tensorflow as tf
23
---> 24 from tensorflow.python.keras.engine import network # pylint: disable=g-direct-tensorflow-import
25
26 from . import activations
ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (/home/user810643/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/__init__.py)

Install tf-agents 0.6.0 version for Tebsorflow 2.3.
pip install tf-agents==0.6.0
Looks like the issue was caused due to TF-Agents and Tensorflow version incompatibility. For more information, please take a look at this release notes. Thanks!

Related

What is wrong - import hvplot.pandas

import hvplot.pandas
import hvplot.pandas
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d0834c846347> in <module>
----> 1 import hvplot.pandas
~\anaconda3\envs\PythonData\lib\site-packages\hvplot\__init__.py in <module>
70 from .converter import HoloViewsConverter
71 from .interactive import Interactive
---> 72 from .ui import explorer # noqa
73 from .utilities import hvplot_extension, output, save, show # noqa
74 from .plotting import (hvPlot, hvPlotTabular, # noqa
~\anaconda3\envs\PythonData\lib\site-packages\hvplot\ui.py in <module>
7 from holoviews.element import tile_sources
8 from holoviews.plotting.util import list_cmaps
----> 9 from panel.viewable import Viewer
10
11 from .converter import HoloViewsConverter as _hvConverter
ImportError: cannot import name 'Viewer'
Uninstalled hvplot
uninstalled holoview
reinstalled - reboot - rerun same error
version hvplot0.8.1
version holoview 1.14.9
install and uninstalls successfull everytime
Any ideas
It is likely that the version of Panel you got installed is one that is pretty old. If you still encounter this issue you should try forcing a recent Panel version with pip/conda install hvplot panel>=0.14.

got "No module named 'tensorflow.python.platform' " when try to import TensorFlow 2.0

I installed the latest anaconda navigator 1.9.7 (windows 10), and created a new env (python 3.7)in the anaconda navigator interface, then installed jupyter notebook and tensorflow 2.0 package in it.
when I tried to import tensorflow as follow
import tensorflow as tf
I got this error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-64156d691fe5> in <module>
----> 1 import tensorflow as tf
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py in <module>
26
27 # pylint: disable=g-bad-import-order
---> 28 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
29 from tensorflow.python.tools import module_util as _module_util
30
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\__init__.py in <module>
47 import numpy as np
48
---> 49 from tensorflow.python import pywrap_tensorflow
50
51 # Protocol buffers
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
23 import traceback
24
---> 25 from tensorflow.python.platform import self_check
26
27
ModuleNotFoundError: No module named 'tensorflow.python.platform'
i tried use
pip uninstall tensorflow
pip install tensorflow
and
redid it inside that directory
nothing worked so far.
any suggestion?
If you clone from git ,you can
just change the folder from the one where you run the configure/bazel and then try python import tensorflow as tf

Module Not Found Error when importing Pytorch_Transformers

After downloading pytorch_transformers through Anaconda and executing the import command through the Jupyter Notebook, I am facing several errors related to missing modules.
I tried searching sacremoses to import the package via Anaconda, but it is only available for Linux machines. Has anyone else faced similar issues? Thanks in advance!
from pytorch_transformers import BertTokenizer, BertModel, BertForMaskedLM
This is the error:
<ipython-input-5-218d0858d00f> in <module>
----> 1 from pytorch_transformers import BertTokenizer, BertModel, BertForMaskedLM
~\Anaconda3\lib\site-packages\pytorch_transformers\__init__.py in <module>
1 __version__ = "1.2.0"
----> 2 from .tokenization_auto import AutoTokenizer
3 from .tokenization_bert import BertTokenizer, BasicTokenizer, WordpieceTokenizer
4 from .tokenization_openai import OpenAIGPTTokenizer
5 from .tokenization_transfo_xl import (TransfoXLTokenizer, TransfoXLCorpus)
~\Anaconda3\lib\site-packages\pytorch_transformers\tokenization_auto.py in <module>
24 from .tokenization_transfo_xl import TransfoXLTokenizer
25 from .tokenization_xlnet import XLNetTokenizer
---> 26 from .tokenization_xlm import XLMTokenizer
27 from .tokenization_roberta import RobertaTokenizer
28 from .tokenization_distilbert import DistilBertTokenizer
~\Anaconda3\lib\site-packages\pytorch_transformers\tokenization_xlm.py in <module>
25 from io import open
26
---> 27 import sacremoses as sm
28
29 from .tokenization_utils import PreTrainedTokenizer
ModuleNotFoundError: No module named 'sacremoses'```
Please try to create a conda environment and install the packages in the created environment using the below steps:
conda create -n env_pytorch -c intel python=3.5
source activate env_pytorch
pip install pytorch-transformers
You are missing the pytorch-transformers dependency. Try installing it with the following command:
pip install pytorch-transformers
Try using python -m pip install transformers rather than using pip install

sklearn model_selection Error: ImportError: cannot import name '_approximate_mode'

I'm trying to import sklearn model_selection but I'm getting the following error:
ImportError Traceback (most recent call last)
<ipython-input-219-6bc6f0a77ca9> in <module>()
----> 1 import sklearn.model_selection
~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/__init__.py in <module>()
----> 1 from ._split import BaseCrossValidator
2 from ._split import KFold
3 from ._split import GroupKFold
4 from ._split import StratifiedKFold
5 from ._split import TimeSeriesSplit
~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_split.py in <module>()
21
22 from ..utils import indexable, check_random_state, safe_indexing
---> 23 from ..utils import _approximate_mode
24 from ..utils.validation import _num_samples, column_or_1d
25 from ..utils.validation import check_array
ImportError: cannot import name '_approximate_mode'
I tried uninstalling scikit-learn and reinstalling it but I get the same error. My current version of scikit-learn is 0.21.2.
Thanks for the help!
I shutdown the kernel and restarted it again. Now it's working fine! Thanks!!
You are using python notebook. I found that error once when I have installed the package before importing. I have tested this at Google AI notebook and worked well.
Save the notebook -> shutdown the kernel -> close and open the notebook again.
You can restart the kernel or use the importlib library
from importlib import reload
sklearn= reload(sklearn)

Using pytables with python3 fails

importing pytables (3.1.1) in python 3.4.1 fails for me, complaining about a failed cPickle import
i try to use potables (3.1.1) with python (3.4.1)
In [1]: import tables
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-389ecae14f10> in <module>()
----> 1 import tables
/work/projects/vEnv/lib/python3.4/site-packages/tables/__init__.py in <module>()
80
81 # Necessary imports to get versions stored on the cython extension
---> 82 from tables.utilsextension import (
83 get_pytables_version, get_hdf5_version, blosc_compressor_list,
84 blosc_compcode_to_compname_ as blosc_compcode_to_compname,
/work/projects/vEnv/lib/python3.4/site-packages/tables/utilsextension.pyx in init tables.utilsextension (tables/utilsextension.c:15600)()
/work/projects/vEnv/lib/python3.4/site-packages/tables/description.py in <module>()
22 import numpy
23
---> 24 from tables import atom
25 from tables.path import check_name_validity
26
/work/projects/vEnv/lib/python3.4/site-packages/tables/atom.py in <module>()
18 import sys
19 import inspect
---> 20 import cPickle
21
22 import numpy
As i understand cPickle is only used instead of pickle in python2.
As of PyTable 3.x it should work fine with python3.x. How can there be a cPickle import than?
What do i have to do to use pytables with python3?
The error was produced most likely due to a problem with my vEnv. Uninstalling the package and reinstalling it fix the problem.
See github issue

Resources