ModuleNotFoundError: No module named 'torch.utils.benchmark' - python

I have been trying to use the torch benchmark module for profiling the code. Verified that all required imports are in place:
import torch
import torchvision
import torch.utils.benchmark
Also, these are the versions installed:
torch -> 1.4.0
torchvision -> 0.2.1
tensorflow -> 1.12.0
tensorflow-gpu -> 1.12.0
tensorboard -> 2.5.0
But I still get error: ModuleNotFoundError: No module named 'torch.utils.benchmark' while importing torch.utils.benchmark. What could be the root cause?

Have you tried to upgrade torch? I see you are using 1.4.0 but currently 1.9.0 is available.
pip install torch --upgrade
I have tested import of modules as you describe with 1.9.0 and receive no errors.

Related

from six.moves import urllib ImportError: No module named six.moves

i have installed six but i got error below:
from six.moves import urllib
ImportError: No module named six.moves
When executing
pip install six.moves
:
Could not find a version that satisfies the requirement six.moves (from versions: )
No matching distribution found for six.moves
i am using python 3.5.6
Tensorflow 1.x is deprecated to use and no longer supported. This could be the reason for the above error.
Please try again by upgrading the tensorflow version to TF 2.x as per this tested build configuration which does not show any error while importing the above package.
You can use below code to install tensorflow
!pip install --upgrade tensorflow #or
!pip install tensorflow==2.2 # can mention specific TF version to install
and then import six package libraries
from six.moves import urllib
Note: This six package get installed automatically while installing tensorflow:

tensorflow import error: No module named tensorflow.python.checkpoint

i'm trying to import tensorflow-hub and i'm getting an error:
ModuleNotFoundError: No module named 'tensorflow.python.checkpoint'
full error message
Apparently the folder tensorflow.python.checkpoint doesn't exist in the tensorflow source code that I installed (though it does exist in the github repository of tensorflow)
I'm using
tensorflow 2.9.1
tensorflow-estimator 2.9.0
tensorflow-hub 0.8.0
Thanks!
it's probably not a permanent solution, but I think downgrading TensforFlow to version 1.15 should help

How to fix "ModuleNotFoundError: No module named 'keras.layers.advanced_activations' "

I'm trying to import imageai
from imageai.Detection import VideoObjectDetection
but get error message below
ModuleNotFoundError: No module named 'keras.layers.advanced_activations'
My tensorflow version 2.9.1,
keras version 2.9.0,
keras-preprocessing version 1.1.2,
image ai version 2.1.5,
I installed the imageai via pip install imageai-2.0.2-py3-none-any.whl and download from here.
The following code is an example for calling several types of advanced activation, Try to call it by
from keras.layers import ELU, PReLU, LeakyReLU
The import works with keras version 2.9.0 as below.
from keras.layers import LeakyReLU
I encountered the same error today. Downgrading my keras to 2.1.0 and tensorflow to 2.2.0 got rid of the error.
I faced the same error. ModuleNotFoundError: No module named 'keras.layers.advanced_activations'
To solve this problem:
Try to install TensorFlow 2.8.2 which is compatible with Keras 2.8.0
pip install tensorflow==2.8.2
Please install imageai using this link or use below code as you must install few libraries before installing imageai.
pip install cython pillow>=7.0.0 numpy>=1.18.1 opencv-python>=4.1.2 torch>=1.9.0 --extra-index-url https://download.pytorch.org/whl/cpu torchvision>=0.10.0 --extra-index-url https://download.pytorch.org/whl/cpu pytest==7.1.3 tqdm==4.64.1 scipy>=1.7.3 matplotlib>=3.4.3 mock==4.0.3
pip install imageai --upgrade
then import VideoObjectDetection as below:
from imageai.Detection import VideoObjectDetection

ModuleNotFoundError: No module named 'mxnet'

I have been looking for the solution for this error for a whole morning. I created an separate environment for python 3.6 and I still got this error. I am using anacondas. So i am so frustrated.
ModuleNotFoundError: No module named 'mxnet'
from gluonts.model.deepar import DeepAREstimator
from gluonts.trainer import Trainer
import mxnet as mx
import numpy as np
np.random.seed(7)
mx.random.seed(7)
estimator = DeepAREstimator(
prediction_length=28,
context_length=100,
freq='H',
trainer=Trainer(ctx="gpu", # remove if running on windows
epochs=5,
learning_rate=1e-3,
num_batches_per_epoch=100
)
)
predictor = estimator.train(train_ds)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-14-d803033f31d5> in <module>
----> 1 from gluonts.model.deepar import DeepAREstimator
2 from gluonts.trainer import Trainer
3 import mxnet as mx
4 import numpy as np
5
~\miniconda3\envs\deepar\lib\site-packages\gluonts\model\deepar\__init__.py in <module>
12 # permissions and limitations under the License.
13
---> 14 from ._estimator import DeepAREstimator
15
16 __all__ = ["DeepAREstimator"]
~\miniconda3\envs\deepar\lib\site-packages\gluonts\model\deepar\_estimator.py in <module>
16
17 import numpy as np
---> 18 from mxnet.gluon import HybridBlock
19
20 from gluonts.core.component import DType, validated
ModuleNotFoundError: No module named 'mxnet'
I installed both gluonts successfully. then I tried to install mxnet by conda install mxnet, there are so many conflicts, not sure why, here are just part of conflicts. Thanks for your help
Package notebook conflicts for:
widgetsnbextension -> notebook[version='>=4.4.1']
jupyter -> notebook
ipywidgets -> widgetsnbextension[version='>=3.5.0,<3.6.0'] -> notebook[version='>=4.4.1']
Package matplotlib-base conflicts for:
matplotlib -> matplotlib-base[version='3.1.2|3.1.2|3.1.2|3.1.3|3.1.3|3.1.3|>=3.2.1,<3.2.2.0a0|>=3.2.2,<3.2.3.0a0|>=3.3.1,<3.3.2.0a0|>=3.4.3,<3.4.4.0a0|>=3.4.2,<3.4.3.0a0|>=3.3.4,<3.3.5.0a0|>=3.3.2,<3.3.3.0a0',build='py36h64f37c6_1|py36h64f37c6_0|py37h64f37c6_0|py38h64f37c6_0|py37h64f37c6_1|py38h64f37c6_1']
gluonts -> matplotlib~=3.0 -> matplotlib-base[version='3.1.2|3.1.2|3.1.2|3.1.3|3.1.3|3.1.3|>=3.2.1,<3.2.2.0a0|>=3.2.2,<3.2.3.0a0|>=3.3.1,<3.3.2.0a0|>=3.4.3,<3.4.4.0a0|>=3.4.2,<3.4.3.0a0|>=3.3.4,<3.3.5.0a0|>=3.3.2,<3.3.3.0a0',build='py36h64f37c6_1|py36h64f37c6_0|py37h64f37c6_0|py38h64f37c6_0|py37h64f37c6_1|py38h64f37c6_1']
Package pandocfilters conflicts for:
notebook -> nbconvert -> pandocfilters[version='>=1.4.1']
nbconvert -> pandocfilters[version='>=1.4.1']
jupyter -> nbconvert -> pandocfilters[version='>=1.4.1']
Package fonttools conflicts for:
matplotlib-base -> fonttools[version='>=4.22.0']
matplotlib -> matplotlib-base[version='>=3.4.3,<3.4.4.0a0'] -> fonttools[version='>=4.22.0']
Package pywinpty conflicts for:
notebook -> terminado[version='>=0.8.1'] -> pywinpty
terminado -> pywinpty
Package sip conflicts for:
matplotlib -> pyqt -> sip[version='4.18.*|>=4.19.4|>=4.19.4,<=4.19.8|4.19.13.*|>=4.19.13,<=4.19.14']
pyqt -> sip[version='4.18.*|>=4.19.4|>=4.19.4,<=4.19.8|4.19.13.*|>=4.19.13,<=4.19.14']
qtconsole -> pyqt -> sip[version='4.18.*|>=4.19.4|>=4.19.4,<=4.19.8|4.19.13.*|>=4.19.13,<=4.19.14']
Package scandir conflicts for:
importlib_metadata -> pathlib2 -> scandir
testpath -> pathlib2 -> scandir
ipython -> pathlib2 -> scandir
pickleshare -> pathlib2 -> scandir
Package olefile conflicts for:
pillow -> olefile
matplotlib-base -> pillow[version='>=6.2.0'] -> olefile
Package pandoc conflicts for:
nbconvert -> pandoc[version='>=1.12.1|>=1.12.1,<2.0.0']
jupyter -> nbconvert -> pandoc[version='>=1.12.1|>=1.12.1,<2.0.0']
notebook -> nbconvert -> pandoc[version='>=1.12.1|>=1.12.1,<2.0.0']
Package async_generator conflicts for:
nbclient -> async_generator
nbconvert -> nbclient[version='>=0.5.0,<0.6.0'] -> async_generator
Conda is more usable when we want to install something that is not written in python. It is not the case in Mxnet. I would suggest using pip install for libraries in python.
You may take a look at this link to better understand how to use conda environments.
What is the difference between pip and conda?
Also here's the official documentation of anaconda:
https://www.anaconda.com/blog/understanding-conda-and-pip
You may go through these. One common trick to understand if we need pip install or conda install, we check if the source code of the library in question is written in python or in another language.
If it is in python, then it's highly recommended to use pip install
Otherwise, conda install.
Here, in https://pypi.org/project/mxnet/ it has been mentioned that the latest version of Mxnet works in all python version from 3.5 onwards, so pip install mxnet should work.
use pip install mxnet. don't use conda install mxnet. if there is an error about permission, then use pip install mxnet --user. It worked for me.
pip install mxnet
Using this will solve your no module name 'mxnet' error.

Can't import Weka in Python

I've tried import weka package in Pycharm. But it got an error.
This is for Python 3.7.4 on windows 10. And I've installed java bridge and Weka successfully.
Package Version
------------------- -------
arff 0.9
javabridge 1.0.18
numpy 1.17.3
pandas 0.25.2
pip 19.3.1
python-dateutil 2.8.0
python-weka-wrapper 0.3.15
pytz 2019.3
setuptools 40.8.0
six 1.12.0
weka 1.0.6
and I type:
import weka.core
and get the error:
File "C:/Users/dell/PycharmProjects/lab2/Source.py", line 2, in <module>
import weka.core
ModuleNotFoundError: No module named 'weka.core'
So how to fix it? Thank you
weka.core is not a Python module, as the error states.
What are you trying to achieve with this import?
If you are trying to import the jvm module (eg for starting/stopping the JVM), then do something like import weka.core.jvm as jvm.

Categories