sphinx-contrib / sphinxcontrib-versioning

Sphinx extension that allows building versioned docs for self-hosting.
https://sphinxcontrib-versioning.readthedocs.io/en/latest/
MIT License
127 stars 80 forks source link

ImportError: cannot import name 'build_main' #66

Open super-sk opened 5 years ago

super-sk commented 5 years ago

Using :

While running any sphinxcontrib-versioning command, I got :

$ sphinx-versioning build --help

...
File "~/.virtualenvs/docs-temp/lib/python3.6/site-packages/sphinxcontrib/versioning/sphinx_.py", line 9, in <module>
    from sphinx import application, build_main, locale
ImportError: cannot import name 'build_main'

It seems like a wrong module call because build_main is not in sphinx package but it can be called from module sphinx.cmd.build.

Indeed, when I manually modify as below :

# versioning/sphinx_.py

from sphinx import build_main              # old line
from sphinx.cmd.build import build_main    # new line

everything seems to go well.

z00sts commented 5 years ago

Fixed here https://github.com/sphinx-contrib/sphinxcontrib-versioning/pull/69

But it seems CI-process is kind of broken.

super-sk commented 5 years ago

The workaround is working, changing from sphinx import build_main to from sphinx.cmd.build import build_main. Should I close the issue right now ?

z00sts commented 5 years ago

@super-sk I don't think so. My PR is still on code review stage, there are some issues with CI-process. Its will be better to keep issue opened

gryphon2411 commented 4 years ago

Any progress on this one?

z00sts commented 4 years ago

@Eido95 waiting for merge here https://github.com/sphinx-contrib/sphinxcontrib-versioning/pull/78

Sachin-Suresh commented 2 years ago

is anyone still facing this issue in 2022? I am getting the same error.

basejumpa commented 2 years ago

Same issue here. I could need the fix as well

$ sphinx-build --version
sphinx-build 5.1.1

$ sphinx-versioning --version
Traceback (most recent call last):
  File "C:\Users\manna\scoop\apps\python\current\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\manna\scoop\apps\python\current\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\manna\scoop\apps\python\current\Scripts\sphinx-versioning.exe\__main__.py", line 4, in <module>
  File "C:\Users\manna\scoop\apps\python\current\lib\site-packages\sphinxcontrib\versioning\__main__.py", line 13, in <module>
    from sphinxcontrib.versioning.routines import build_all, gather_git_info, pre_build, read_local_conf
  File "C:\Users\manna\scoop\apps\python\current\lib\site-packages\sphinxcontrib\versioning\routines.py", line 11, in <module>
    from sphinxcontrib.versioning.sphinx_ import build, read_config
  File "C:\Users\manna\scoop\apps\python\current\lib\site-packages\sphinxcontrib\versioning\sphinx_.py", line 9, in <module>
    from sphinx import application, build_main, locale
ImportError: cannot import name 'build_main' from 'sphinx' (C:\Users\manna\scoop\apps\python\current\lib\site-packages\sphinx\__init__.py)

For the time being I'll be using https://pypi.org/project/sphinx-multiversion/

NikosAlexandris commented 1 year ago

Same issue here with

❯ sphinx-build --version
sphinx-build 5.0.2

and

❯ sphinx-versioning --version
Traceback (most recent call last):
  File "/home/nik/.local/bin/sphinx-versioning", line 5, in <module>
    from sphinxcontrib.versioning.__main__ import cli
  File "/home/nik/.local/lib/python3.10/site-packages/sphinxcontrib/versioning/__main__.py", line 13, in <module>
    from sphinxcontrib.versioning.routines import build_all, gather_git_info, pre_build, read_local_conf
  File "/home/nik/.local/lib/python3.10/site-packages/sphinxcontrib/versioning/routines.py", line 11, in <module>
    from sphinxcontrib.versioning.sphinx_ import build, read_config
  File "/home/nik/.local/lib/python3.10/site-packages/sphinxcontrib/versioning/sphinx_.py", line 9, in <module>
    from sphinx import application, build_main, locale
ImportError: cannot import name 'build_main' from 'sphinx' (/home/nik/.local/lib/python3.10/site-packages/sphinx/__init__.py)
waltsims commented 1 year ago

same issue here:

$ sphinx-build --version
sphinx-build 5.3.0
adam-grant-hendry commented 1 year ago

Same issue here:

OS: Windows 10 python: 3.8.10 sphinx: 6.2.1 sphinxcontrib-versioning: 2.2.1