d2l-ai / d2l-book

Books with Jupyter notebooks

Home Page:https://book.d2l.ai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] ModuleNotFoundError: No module named 'sphinx'

AnirudhDagar opened this issue · comments

When installing d2lbook in a completely new environment with sphinx not cached by previous pip installations, the following error is raised:

Collecting mxtheme>=0.3.16
  Downloading mxtheme-0.3.16.tar.gz (8.3 MB)
    ERROR: Command errored out with exit status 1:
     command: /home/d2l-worker/miniconda3/envs/d2l-en-master-0/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-sjca2a5v
         cwd: /tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/setup.py", line 2, in <module>
        from mxtheme import __version__
      File "/tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/mxtheme/__init__.py", line 2, in <module>
        from .card import CardDirective
      File "/tmp/pip-install-g2gp4y2_/mxtheme_a6ceecb6302d4ebaa879512c5d3e27b6/mxtheme/card.py", line 1, in <module>
        from sphinx.locale import _
    ModuleNotFoundError: No module named 'sphinx'
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/ed/74/9bdb93269b054b9aefdc16b91e8ec8603afa16ba2036cdd5a10c5b0c9c71/mxtheme-0.3.16.tar.gz#sha256=e3524a6ea78f56686b14c866539aa49c8507b01ab414937454a7fbe6b55aaeac (from https://pypi.org/simple/mxtheme/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mxtheme>=0.3.16 (from d2lbook) (from versions: 0.3.2, 0.3.3, 0.3.5, 0.3.6, 0.3.7, 0.3.8, 0.3.9, 0.3.10, 0.3.11, 0.3.12, 0.3.13, 0.3.14, 0.3.15, 0.3.16)
ERROR: No matching distribution found for mxtheme>=0.3.16
script returned exit code 1

Attaching an example failed CI Log here.
This is because d2lbook depends on sphinx and mxtheme is also one of the d2lbook dependencies which depends on sphinx.

The issue is caused by version import in setup.py - even if sphinx dependency is present in requirements, it won't be installed prior because setup is broken: https://github.com/d2l-ai/d2l-book/blob/master/setup.py#L2

@gradientsky it's actually not the d2lbook setup. It is the mxtheme setup that is broken because it has a hard requirement on sphinx inside init.py file. And during it's setup, just to get the version the following line:

from mxtheme import __version__

throws an error because as soon as mxtheme is imported, init is invoked. Even though design wise I do not advocate importing the package in the setup.py file, and I'm totally with you on that, but here d2lbook init file doesn't depend on anything so technically it should run without issues.

I can send a fix in mxtheme for this, requiring sphinx at install time and using a better design to read version in setup.py. cc @mli @astonzhang