d2l-ai / d2l-en

Interactive deep learning book with multi-framework code, math, and discussions. Adopted at 500 universities from 70 countries including Stanford, MIT, Harvard, and Cambridge.
https://D2L.ai
Other
23.94k stars 4.36k forks source link

d2l setup.py should include mxnet as depency with appropriate version #674

Closed mohamed-ali closed 4 years ago

mohamed-ali commented 4 years ago

After setting up a conda environment with all the required dependencies, running d2lbook build html fails with the error message:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ccff59c9a15f> in <module>
      1 get_ipython().run_line_magic('matplotlib', 'inline')
----> 2 import d2l
      3 from IPython import display
      4 import numpy as np
      5 

~/Desktop/workspace/d2l-en/d2l/__init__.py in <module>
----> 1 from .d2l import *
      2 
      3 __version__ = '0.11.1'

~/Desktop/workspace/d2l-en/d2l/d2l.py in <module>
     12 import math
     13 from matplotlib import pyplot as plt
---> 14 from mxnet import autograd, context, gluon, image, init, np, npx
     15 from mxnet.gluon import nn, rnn
     16 import os

ModuleNotFoundError: No module named 'mxnet'
ModuleNotFoundError: No module named 'mxnet'

Attempting to solve this problem with pip install mxnet doesn't work, because d2l isn't using the stable released version of mxnet

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ccff59c9a15f> in <module>
      1 get_ipython().run_line_magic('matplotlib', 'inline')
----> 2 import d2l
      3 from IPython import display
      4 import numpy as np
      5 

~/Desktop/workspace/d2l-en/d2l/__init__.py in <module>
----> 1 from .d2l import *
      2 
      3 __version__ = '0.11.1'

~/Desktop/workspace/d2l-en/d2l/d2l.py in <module>
     12 import math
     13 from matplotlib import pyplot as plt
---> 14 from mxnet import autograd, context, gluon, image, init, np, npx
     15 from mxnet.gluon import nn, rnn
     16 import os

ImportError: cannot import name 'np' from 'mxnet' (/Users/.../miniconda3/envs/d2lai/lib/python3.7/site-packages/mxnet/__init__.py)
ImportError: cannot import name 'np' from 'mxnet' (/Users/.../miniconda3/envs/d2lai/lib/python3.7/site-packages/mxnet/__init__.py)

I think mxnet should be added to the setup.py of d2l as a dependency. The appropriate mxnet version should be specified as well to avoid this issue in the future.

What do you think?

PS: installing pre released mxnet version solves the problem.

pip install mxnet --pre

Thanks.

astonzhang commented 4 years ago

Thanks. In https://d2l.ai/chapter_installation/index.html, we separate the installation of mxnet from dependency of d2l's setup. This will allow users to specify the CPU version or a certain cuda version of mxnet based on their preference.

mohamed-ali commented 4 years ago

Thanks for clarifying. That seems reasonable.