Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Failed with Relatively New Python 3.8 Installation on Windows 10 #2214

Closed
vwheeler63 opened this issue Sep 11, 2024 · 6 comments
Closed

Comments

@vwheeler63
Copy link
Collaborator

vwheeler63 commented Sep 11, 2024

Hello!

I have been learning Sphinx and came across the writethedocs/www repository and forked, then cloned my fork. I'm on a Windows 10 system and have several unix-like environments, but am working from the Windows Command Prompt with GNU-Windows utilities.

I followed the instructions in the README on https://github.com/writethedocs/www

  • Installed Python 3.8, and set my path variables to point to it (they normally point to Python 3.12).
  • I didn't have virtualenv, so I did (in the top www directory):
> python -m venv venv
> venv\scripts\activate.bat
(venv) > python -m pip install --upgrade pip
(venv) > pip install -r requirements.txt

...which succeeded without error. Then I tried:

(venv) > cd docs
(venv) > make clean
(venv) > make html

and got this:

(venv) \path\to\writethedocs\www\docs>make html
Running Sphinx v4.5.0

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\config.py", line 332, in eval_config_file
    exec(code, namespace)
  File "E:\Dev\Clients\WGA\writethedocs\www\docs\conf.py", line 12, in <module>
    reload(sys)
NameError: name 'reload' is not defined


Build finished. The HTML pages are in _build/html.

I tried:

(venv) > make livehtml

which generated this error:

usage: sphinx-autobuild [-h] [--port PORT] [--host HOST] [--re-ignore RE_IGNORE] [--ignore IGNORE] [--no-initial] [--open-browser]
                        [--delay DELAY] [--watch DIR] [--pre-build COMMAND] [--version]
                        sourcedir outdir [filenames [filenames ...]]
sphinx-autobuild: error: unrecognized arguments: -p -z . _build/html

I am hoping you have run into this before. As a test I tried commenting out the reload(sys) line in conf.py, but then it has a similar error on the line below. it.

Is this perhaps due to a missing prerequisite?

Kind regards,
Vic

@plaindocs
Copy link
Contributor

I'm afraid most of us don't have a lot of experience with the Windows side of things.

Looks like it could be something similar to this ancient stuff. https://stackoverflow.com/questions/10142764/nameerror-name-reload-is-not-defined

In which case, try

import importlib
importlib.reload(sys)

instead of

reload(sys)

@vwheeler63
Copy link
Collaborator Author

@plaindocs Alas, I know too little about Python and Sphinx to be really effective at debugging this.

from importlib import reload

allows the reload(sys) to run, but then the sys.setdefaultencoding('UTF8') fails with the same error message (not there), so it may not be the same reload().

Doing a little reading:

  • The reload(sys) is apparently aimed at restoring the sys.setdefaultencoding('UTF8') after it was removed by sitecustomize.py during Python initialization.
  • Python 3 is already set up to have all its encoding (I think) in UTF-8, and the sys.setdefaultencoding('UTF8') appears to be a work-around for some Python (v2?) modules that use ASCII encoding by default -- if I am understanding what I read correctly.

When I comment out those lines (the if os.name == 'nt' block), sphinx runs for a while and then generates this error (which I think is what sys.setdefaultencoding('UTF8') is trying to address):

Encoding error:
'charmap' codec can't decode byte 0x9d in position 7746: character maps to <undefined>
The full traceback has been saved in R:\TMPDIR\sphinx-err-j153dqok.log, if you want to report the issue to the developers.

and the end of that log file is showing this:

File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\yaml\reader.py", line 178, in update_raw
    data = self.stream.read(size)
  File "C:\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 7746: character maps to <undefined>

which makes me think a YAML module (venv\lib\site-packages\yaml\reader.py) is using code-page 1252 ((cp1252.py) which I believe is ASCII encoding), and I suspect the sys.setdefaultencoding('UTF8') get that module it to use UTF-8 encoding instead.

I've run out of time to dig into this, but when I get some more time, I will try to report back here when I find a solution.

I've attached the full trace-back log in case you'd like to have a look at it.

sphinx-err-o7z9z4p9.log

Kind regards,
Vic

@vwheeler63 vwheeler63 changed the title Building Failed with Relatively New Python 3 Installation Building Failed with Relatively New Python 3 Installation on Windows 10 Sep 12, 2024
@vwheeler63 vwheeler63 changed the title Building Failed with Relatively New Python 3 Installation on Windows 10 Building Failed with Relatively New Python 3.8 Installation on Windows 10 Sep 18, 2024
@vwheeler63
Copy link
Collaborator Author

Now that Kevin has successfully handled THAT exception (thank you @kdschlosser), I got another 16% of the way through the build (up to 31% completed) and the next exception was this one, I'm guessing due to a similar reason....

Traceback (most recent call last):
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\events.py", line 94, in emit
    results.append(listener.handler(self.app, *args))
  File "E:\Dev\Clients\WGA\writethedocs\www\docs\_ext\core.py", line 214, in render_rst_with_jinja
    conf_context = load_conference_page_context(app, docname)
  File "E:\Dev\Clients\WGA\writethedocs\www\docs\_ext\core.py", line 54, in load_conference_page_context
    context = load_conference_context_from_yaml(shortcode, year, year_str, page)
  File "E:\Dev\Clients\WGA\writethedocs\www\docs\_ext\core.py", line 137, in load_conference_context_from_yaml
    schedule_item['time'] = naive_item_start.strftime(TIME_FORMATS[data['time_format']])
ValueError: Invalid format string

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\cmd\build.py", line 276, in build_main
    app.build(args.force_all, filenames)
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\application.py", line 330, in build
    self.builder.build_update()
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\builders\__init__.py", line 286, in build_update
    self.build(to_build,
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\builders\__init__.py", line 300, in build
    updated_docnames = set(self.read())
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\builders\__init__.py", line 407, in read
    self._read_serial(docnames)
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\builders\__init__.py", line 428, in _read_serial
    self.read_doc(docname)
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\builders\__init__.py", line 468, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\io.py", line 181, in read_doc
    pub.publish()
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\docutils\core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\io.py", line 100, in read
    self.input = self.read_source(settings.env)
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\io.py", line 110, in read_source
    env.events.emit('source-read', env.docname, arg)
  File "e:\dev\clients\wga\writethedocs\www\venv\lib\site-packages\sphinx\events.py", line 102, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function render_rst_with_jinja at 0x0000028F9BFD7280> for event 'source-read' threw an exception (exception: Invalid format string)

Extension error (_ext.core):
Handler <function render_rst_with_jinja at 0x0000028F9BFD7280> for event 'source-read' threw an exception (exception: Invalid format string)

@kdschlosser
Copy link
Contributor

#2228 should correct the latest error. give it a try and lemme know if it works for you..

@kdschlosser
Copy link
Contributor

@vwheeler63

I think you can close this now. All of the issues with compiling under Windows has been addressed yes? If there is anything else lemme know and I will be more then happy to help with it..

@vwheeler63
Copy link
Collaborator Author

@vwheeler63

I think you can close this now. All of the issues with compiling under Windows has been addressed yes? If there is anything else lemme know and I will be more then happy to help with it..

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants