4

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

roudan
  • 3,082
  • 5
  • 31
  • 72
  • 1
    Conda is really something that's not easy to understand. Even we gave up on it and started using pyenv or virtualenv. As far as your issue is concerned, in my knowledge, it has got to be associated with the python being as old as 3.6. Is it absolutely necessary for you to use conda install ? 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. – Keshav Biyani Nov 06 '21 at 18:51
  • ok, thanks Keshav, let me try to install using pip to see – roudan Nov 06 '21 at 19:04
  • Hi Keshav, yes using pip worked. pip install mxnet. Thank you so much for your help. It saved me tons of time. I appreciate it. – roudan Nov 06 '21 at 19:09

3 Answers3

2

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.

roudan
  • 3,082
  • 5
  • 31
  • 72
2

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.

Keshav Biyani
  • 235
  • 1
  • 10
  • 1
    great to know when to use pip and when to use conda. Thank you Heshav – roudan Nov 06 '21 at 19:17
  • one more thing Kdeshav, is there an easy way to find if a library is written in python or other language? Thanks – roudan Nov 06 '21 at 19:20
  • 1
    In case we don't find the source code (which nowadays is rare, since almost everything is open source w.r.t libraries) we may search for the library in https://pypi.org . If the library in question if present there, then it is written in python and ```pip install``` should work. When we search for a library there, it takes us to a page where we are allowed to put in many filters, of which programming language is one. We check it there. Will get back if we get a more comprehensive way. But this is what we do. Hope it helps. – Keshav Biyani Nov 06 '21 at 19:27
2
pip install mxnet

Using this will solve your no module name 'mxnet' error.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Fenil
  • 39
  • 3