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.
Related
I am trying to run a ".py" file on windows 10 with tensorflow version 2.8.0 and keras version 2.3.4, where I am calling libraries as follows
from tensorflow import keras
from keras.models import load_model
However, I am getting an error message "ModuleNotFoundError: No module named 'keras.api'"
as shown in the error log below.
DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.log import debug
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\saniy\OneDrive\Derma-Project\app1.py", line 5, in <module>
from keras.models import load_model
File "C:\Python310\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Python310\lib\site-packages\keras\utils\__init__.py", line 26, in <module>
from .vis_utils import model_to_dot
File "C:\Python310\lib\site-packages\keras\utils\vis_utils.py", line 7, in <module>
from ..models import Model
File "C:\Python310\lib\site-packages\keras\models.py", line 12, in <module>
from .engine.training import Model
File "C:\Python310\lib\site-packages\keras\engine\__init__.py", line 8, in <module>
from .training import Model
File "C:\Python310\lib\site-packages\keras\engine\training.py", line 14, in <module>
from . import training_utils
File "C:\Python310\lib\site-packages\keras\engine\training_utils.py", line 17, in <module>
from .. import metrics as metrics_module
File "C:\Python310\lib\site-packages\keras\metrics.py", line 1850, in <module>
BaseMeanIoU = tf.keras.metrics.MeanIoU
File "C:\Python310\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 58, in __getattr__
module = self._load()
File "C:\Python310\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 41, in _load
module = importlib.import_module(self.__name__)
File "C:\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'keras.api'
I am wondering if you can help in this regard.
I am not sure how keras 2.3.4 is installed but minimum version of keras for tf 2.8 is 2.8; Just upgrade your keras version
pip install keras==2.8
Since version 2 of Tensorflow (TF), the Keras package comes installed alongside. Meaning that if you make pip install tensorflow, will install the latest TF version (2.8) and Keras 2.8. As the other answer suggests, I would guess you have some old Keras version installed on your computer.
My advise would be to create a fresh virtual environment,
python3 -m venv ENV_DIR
and then freshly install all the requirements that your .py file needs from scratch. This will hopefully solve your issue and it is also best practice not to mess with different Python packages versions throughout your projects.
I'm trying to use the responder package (https://github.com/taoufik07/responder) in a conda environment. But I'm getting the following error:
conda create --name tmp python=3.7
conda activate tmp
conda install -c conda-forge responder
python -c "import responder;"
And then I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/responder/__init__.py", line 1, in <module>
from .core import *
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/responder/core.py", line 1, in <module>
from .api import API
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/responder/api.py", line 20, in <module>
from . import models, status_codes
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/responder/models.py", line 12, in <module>
import graphene
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/graphene/__init__.py", line 19, in <module>
from .types import (
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/graphene/types/__init__.py", line 7, in <module>
from .scalars import Scalar, String, ID, Int, Float, Boolean
File "/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/graphene/types/scalars.py", line 2, in <module>
from graphql.language.ast import (BooleanValue, FloatValue, IntValue,
ImportError: cannot import name 'BooleanValue' from 'graphql.language.ast' (/Users/x/opt/anaconda3/envs/dex/lib/python3.7/site-packages/graphql/language/ast.py)
I think You haven't activated the Conda environment
MANUAL PROCESS
above error is not module error that import error so in that module something is missing go to the site-packages and into that library then check the code
REINSTALLING
remove that library, and re-install through the pip OR below command, check the python version.
$ pipenv install responder
$ pipenv install -e git+https://github.com/taoufik07/responder.git#egg=responder
I just did a conda install of a few packages to follow a tutorial, and now I can't even import pandas.
I installed these:
fake-factory==0.7.2
Faker==0.7.3
pytz==2016.7
tzlocal==1.3.0
And now I get this:
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\api.py", line 7, in <module>
from pandas.core.arrays.integer import (
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\arrays\__init__.py", line 2, in <module>
from .base import (ExtensionArray, # noqa
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\arrays\base.py", line 21, in <module>
from pandas.core import ops
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\ops\__init__.py", line 21, in <module>
from pandas.core.construction import extract_array
File "C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\construction.py", line 18, in <module>
from pandas.core.dtypes.base import ExtensionDtype, registry
ImportError: cannot import name 'registry' from 'pandas.core.dtypes.base' (C:\ProgramData\Anaconda3\envs\ariel\lib\site-packages\pandas\core\dtypes\base.py)
I tried doing a conda update pandas, but to no avail.
I also just installed luigi, not quite sure when it broke as I installed all the additional packages in one go.
Updated version of pandas package using pip3
try this in python3
pip3 install --upgrade pandas
Try updating pandas package in Anaconda:
conda install pandas=1.1.4
If no luck, try updating all packages:
conda update --all
Worked in my case.
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.
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