I found ModuleNotFoundError: No module named 'tensorflow.contrib' - python

I try to run python on CMD.
I import tensorflow.contrib in my python file.
import tensorflow.contrib.tensorrt as trt
when running on anaconda with this command.
python run_webcam.py --camera yoga.mp4
it show error:
File "run_webcam.py", line 8, in <module>
from tf_pose.estimator import TfPoseEstimator
File "D:\work\pose estimation\tf-pose-estimation\tf_pose\__init__.py", line 5, in <module>
from tf_pose.runner import infer, Estimator, get_estimator
File "D:\work\pose estimation\tf-pose-estimation\tf_pose\runner.py", line 8, in <module>
from tf_pose import eval
File "D:\work\pose estimation\tf-pose-estimation\tf_pose\eval.py", line 13, in <module>
from tf_pose.estimator import TfPoseEstimator
File "D:\work\pose estimation\tf-pose-estimation\tf_pose\estimator.py", line 14, in <module>
import tensorflow.contrib.tensorrt as trt
ModuleNotFoundError: No module named 'tensorflow.contrib'
I installed
pip install tensorflow
and change the version of tensorflow (Try to uninstall and install many version )
pip uninstall tensorflow
pip install tensorflow==...
but show the same error

Try replacing the following
import tensorflow.contrib.tensorrt as trt (used in ≤ TensorFlow 1.13.1 )
with
from tensorflow.python.compiler.tensorrt import trt(TensorFlow ≥ 1.14.1)
Credit to GitHub

Related

TensorFlow ModuleNotFoundError: No module named 'official.nlp.bert'

I'm following the TenslorFlow TFlite basic text classification tutorial, but the third import line throws an error:
from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
ModuleNotFoundError: No module named 'official.nlp.bert'
I installed TensorFlow with pip install tensorflow and the tflite model maker with pip install -q tflite-model-maker.
I've also installed all the official models with pip install tf-models-official.
I can see the BERT model on the official models GitHub as well, so it should be in there.
How can I install the bert model?
Full error:
Traceback (most recent call last):
File "...\Downloads\tf_setup.py", line 6, in <module>
from tflite_model_maker import model_spec
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tflite_model_maker\__init__.py", line 16, in <module>
from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\__init__.py", line 17, in <module>
from tensorflow_examples.lite.model_maker.core.data_util import text_dataloader
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\data_util\text_dataloader.py", line 31, in <module>
from tensorflow_examples.lite.model_maker.core.task import model_spec as ms
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_spec.py", line 37, in <module>
from official.nlp.bert import configs as bert_configs
ModuleNotFoundError: No module named 'official.nlp.bert'
What is your Python version? I encountered the exact same error while I was using Python 3.10. My tflite-model-maker was 0.1.x version despite I tried to install the latest one which is 0.4.0. I wanted to update it but I got more errors about "No matching distribution" for tflite-model-maker and tflite-support. After I installed and changed my Python interpreter (I'm using PyCharm) to Python 3.9.13 and reinstall tflite-model-maker, the error is gone.

ModuleNotFoundError: No module named 'pyasn1'

File "D:\Documents\my_project\firebase_login.py", line 1, in <module>
from pyrebase import pyrebase
File "D:\Documents\Python_projects\Test_kivy\venv\lib\site-packages\pyrebase\__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "D:\Documents\Python_projects\Test_kivy\venv\lib\site-packages\pyrebase\pyrebase.py", line 17, in <module>
from oauth2client.service_account import ServiceAccountCredentials
File "D:\Documents\Python_projects\Test_kivy\venv\lib\site-packages\oauth2client\service_account.py", line 26, in <module>
from oauth2client import crypt
File "D:\Documents\Python_projects\Test_kivy\venv\lib\site-packages\oauth2client\crypt.py", line 23, in <module>
from oauth2client import _pure_python_crypt
File "D:\Documents\Python_projects\Test_kivy\venv\lib\site-packages\oauth2client\_pure_python_crypt.py", line 22, in <module>
from pyasn1.codec.der import decoder
ModuleNotFoundError: No module named 'pyasn1'
Process finished with exit code 1
My code was working like a charm yesterday, today I'm not able to launch it due to pyrebase crashing.
I have this error coming from a PyCharm project.
Pyrebase4: v4.5.0 https://github.com/nhorvath/Pyrebase4
I had the same problem, i solved updating pip.
I also found a similar import issue open on github.
python -m ensurepip
python get-pip.py
pip install awscli --ignore-installed six
ModuleNotFoundError: No module named 'pyasn1_modules'
pip install pyasn1_modules
ModuleNotFoundError: No module named 'google.protobuf'
pip install protobuf

ImportError: cannot import name 'app_settings' from 'leaflet'

I was running django project in Anaconda prompt and I got the following error:
File "C:\Users\hp\geoportal_geodjango\mysite\polls\admin.py", line 4, in <module>
from leaflet.admin import LeafletGeoAdmin
File "C:\ProgramData\Anaconda3\lib\site-packages\leaflet\admin.py", line 17, in <module>
from .forms.widgets import LeafletWidget
File "C:\ProgramData\Anaconda3\lib\site-packages\leaflet\forms\widgets.py", line 15, in <module>
from leaflet import app_settings, PLUGINS, PLUGIN_FORMS
ImportError: cannot import name 'app_settings' from 'leaflet' (C:\ProgramData\Anaconda3\lib\site-packages\leaflet\__init__.py)
I tried different leaflet versions.
just use pip install django-leaflet==0.19.0 and it will uninstall the Django-leaflet you installed and install v 0.19.0
Even if you have v0.19 installed, uninstall it and the install it again

AttributeError: module 'tensorflow' has no attribute 'compat'

Since my CPU doesn't support AVX instructions and I want to install a newer version of Tensorflow (>= 2.0), I installed a tensorflow wheel for my Python version from https://github.com/fo40225/tensorflow-windows-wheel using pip
However, when trying to import tensorflow, I get the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 45, in <module>
from . _api.v2 import compat
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 23, in <module>
from . import v1
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 664, in <module>
from tensorflow_estimator.python.estimator.api._v1 import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
from tensorflow_estimator._api.v1 import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
from tensorflow_estimator._api.v1.estimator import experimental
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 33, in <module>
from tensorflow_estimator.python.estimator import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 53, in <module>
from tensorflow_estimator.python.estimator import util as estimator_util
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\util.py", line 75, in <module>
class _DatasetInitializerHook(tf.compat.v1.train.SessionRunHook):
AttributeError: module 'tensorflow' has no attribute 'compat'
I have searched, but not found anybody who encountered the same issue using tensorflow wheel (just trying to install tensorflow via "pip install tensorflow" isn't going to work for me, as I will run into the ImportError: DLL load failed-error).
It seems tensorflow is not installed in your system in the proper way which causes this error.
You need to install tensorflow using any of the below command:
pip install tensorflow
pip install tensorflow-gpu # to install tensorflow for gpu support
pip install tensorflow==2.4.0 # to install a specific tensorflow version
For Anaconda environment in jupyter notebook, use below code:
conda install tensorflow
conda install tensorflow-gpu # to install tensorflow for gpu support
Please follow this link which has step wise instructions to install tensorflow in your system.

Using tenorflow and python-not finding modules

When running my python code, i get the following error,
File "run_webcam.py", line 8, in <module>
from tf_pose.estimator import TfPoseEstimator
File __init__.py", line 5, in <module>
from tf_pose.runner import infer, Estimator, get_estimator
File runner.py", line 8, in <module>
from tf_pose import eval
File eval.py", line 14, in <module>
from tf_pose.networks import model_wh, get_graph_path
File networks.py", line 6, in <module>
from tf_pose.network_mobilenet import MobilenetNetwork
File network_mobilenet.py", line 5, in <module>
from tf_pose import network_base
File network_base.py", line 8, in <module>
import tensorflow.contrib.slim as slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
I think that i need to import the dependencies differently as i am using tensorflow 2.0.0 and python 3.7.3.
how do i for example change the slim import to work correctly?
Run following commands to solve this issue:
conda create -n tfpose python=3.6 pip
conda activate tfpose
pip uninstall tensorflow
pip install tensorflow
conda install tensorflow
Now execute your python code.

Categories