Issues

Issue #1411 wontfix

Sphinx 1.2.2 project build error using python 3.1

Anonymous created an issue

Right after installing Sphinx 1.2.2 and creating a new project using sphinx-quickstart, I get this :

$ make doc
sphinx-build -b html -d build/doctrees   . build/html
Running Sphinx v1.2.2

Exception occurred:
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/util/pycompat.py", line 94, in execfile_
    filepath_enc = filepath.encode(fs_encoding, encoding='UTF-8')
TypeError: encode() takes no keyword arguments
The full traceback has been saved in /tmp/sphinx-err-Hl8y31.log, if you want to report the issue to the developers.

Well this is the trace :

# Sphinx version: 1.2.2
# Python version: 3.1.2
# Docutils version: 0.11 release
# Jinja2 version: 2.6
# Loaded extensions:
Traceback (most recent call last):
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/cmdline.py", line 253, in main
    warningiserror, tags, verbosity, parallel)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/application.py", line 107, in __init__
    confoverrides or {}, self.tags)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/config.py", line 229, in __init__
    execfile_(filename, config)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/util/pycompat.py", line 96, in execfile_
    code = compile(source, filepath_enc, 'exec')
TypeError: compile() argument 2 must be string, not bytes

I have found a working solution :

$ gksu gedit /usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/util/pycompat.py
then add line 95, just before 'try:'
        filepath_enc = str(filepath_enc, encoding='UTF-8')

The bug does not happen on other machines using python 3.2 or 3.3. So why using python 3.1 ? Because I have Ubuntu 10.04 LTS on it and cannot upgrade right now.

I have not checked if my solution works for other python versions, sorry.

Thanks for all the good job, sphinx is great! I'm just wondering why the "intelligent toolbar" js code is not given in the options, but must be tweaked from the sphinx-doc page ?

Comments (8)

  1. edouard_thiel

    There is a small error in the beginning of my message, and I don't know how to correct; please replace 'doc' by 'html':

    Right after installing Sphinx 1.2.2 and creating a new project using sphinx-quickstart, I get this :

    $ make html

    sphinx-build -b html -d build/doctrees . build/html Running Sphinx v1.2.2

  2. Georg Brandl repo owner

    I don't understand the first traceback. The code does not appear in the source, did that appear after a change of yours?

    In general, I'm not too keen on supporting Python 3.1 -- it is quite dead upstream and has many such small incompatibilities.

  3. edouard_thiel

    I checked with a fresh install on Sphinx 1.2.2; here is the complete traceback; agree that python 3.1 is old but still used on a number of machines ..not always possible to upgrade. With the little correction everything works using python 3.1. It also works (on another machine) using python 3.2.3.

    thiel@capri:~$ sphinx-quickstart 
    Welcome to the Sphinx 1.2.2 quickstart utility.
    
    Please enter values for the following settings (just press Enter to
    accept a default value, if one is given in brackets).
    
    Enter the root path for documentation.
    > Root path for the documentation [.]: foo
    
    You have two options for placing the build directory for Sphinx output.
    Either, you use a directory "_build" within the root path, or you separate
    "source" and "build" directories within the root path.
    > Separate source and build directories (y/n) [n]:
    
    Inside the root directory, two more directories will be created; "_templates"
    for custom HTML templates and "_static" for custom stylesheets and other static
    files. You can enter another prefix (such as ".") to replace the underscore.
    > Name prefix for templates and static dir [_]:
    
    The project name will occur in several places in the built documentation.
    > Project name: bar
    > Author name(s): me
    
    Sphinx has the notion of a "version" and a "release" for the
    software. Each version can have multiple releases. For example, for
    Python the version is something like 2.5 or 3.0, while the release is
    something like 2.5.1 or 3.0a1.  If you don't need this dual structure,
    just set both to the same value.
    > Project version: 1
    > Project release [1]:
    
    The file name suffix for source files. Commonly, this is either ".txt"
    or ".rst".  Only files with this suffix are considered documents.
    > Source file suffix [.rst]:
    
    One document is special in that it is considered the top node of the
    "contents tree", that is, it is the root of the hierarchical structure
    of the documents. Normally, this is "index", but if your "index"
    document is a custom template, you can also set this to another filename.
    > Name of your master document (without suffix) [index]:
    
    Sphinx can also add configuration for epub output:
    > Do you want to use the epub builder (y/n) [n]:
    
    Please indicate if you want to use one of the following Sphinx extensions:
    > autodoc: automatically insert docstrings from modules (y/n) [n]: 
    > doctest: automatically test code snippets in doctest blocks (y/n) [n]: 
    > intersphinx: link between Sphinx documentation of different projects (y/n) [n]: 
    > todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: 
    > coverage: checks for documentation coverage (y/n) [n]: 
    > pngmath: include math, rendered as PNG images (y/n) [n]: 
    > mathjax: include math, rendered in the browser by MathJax (y/n) [n]: 
    > ifconfig: conditional inclusion of content based on config values (y/n) [n]: 
    > viewcode: include links to the source code of documented Python objects (y/n) [n]:
    
    A Makefile and a Windows command file can be generated for you so that you
    only have to run e.g. `make html' instead of invoking sphinx-build
    directly.
    > Create Makefile? (y/n) [y]: 
    > Create Windows command file? (y/n) [y]:
    
    Creating file foo/conf.py.
    Creating file foo/index.rst.
    Creating file foo/Makefile.
    Creating file foo/make.bat.
    
    Finished: An initial directory structure has been created.
    
    You should now populate your master file foo/index.rst and create other documentation
    source files. Use the Makefile to build the docs, like so:
       make builder
    where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
    
    thiel@capri:~$ cd foo
    thiel@capri:~/foo$ make html
    sphinx-build -b html -d _build/doctrees   . _build/html
    Making output directory...
    Running Sphinx v1.2.2
    
    Exception occurred:
      File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/util/pycompat.py", line 96, in execfile_
        code = compile(source, filepath_enc, 'exec')
    TypeError: compile() argument 2 must be string, not bytes
    The full traceback has been saved in /tmp/sphinx-err-eug3Hv.log, if you want to report the issue to the developers.
    Please also report this if it was a user error, so that a better error message can be provided next time.
    A bug report can be filed in the tracker at <https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
    make: *** [html] Erreur 1
    thiel@capri:~/foo$ 
    thiel@capri:~/foo$ cat /tmp/sphinx-err-eug3Hv.log
    # Sphinx version: 1.2.2
    # Python version: 3.1.2
    # Docutils version: 0.11 release
    # Jinja2 version: 2.6
    # Loaded extensions:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/cmdline.py", line 253, in main
        warningiserror, tags, verbosity, parallel)
      File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/application.py", line 107, in __init__
        confoverrides or {}, self.tags)
      File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/config.py", line 229, in __init__
        execfile_(filename, config)
      File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.2.2-py3.1.egg/sphinx/util/pycompat.py", line 96, in execfile_
        code = compile(source, filepath_enc, 'exec')
    TypeError: compile() argument 2 must be string, not bytes
    
  4. Takayuki Shimizukawa

    I confirmed. The issue is caused by Python-3.1.2 or earlier 3.1.x version. Python-3.1.3 or later versions doesn't cause the issue.

    $ python312
    Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> compile('', 'conf.py', 'exec')
    <code object <module> at 0x00000000021CF930, file "conf.py", line 1>
    >>> compile('', b'conf.py', 'exec')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: compile() argument 2 must be string, not bytes
    
    $ python313
    Python 3.1.3 (r313:86834, Nov 27 2010, 17:20:37) [MSC v.1500 64 bit (AMD64)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> compile('', b'conf.py', 'exec')
    <code object <module> at 0x000000000220EC30, file "conf.py", line 1>
    >>> compile('', 'conf.py', 'exec')
    <code object <module> at 0x0000000002220F30, file "conf.py", line 1>
    

    However I can't find a CHANGES for that: http://svn.python.org/projects/python/tags/r313/Misc/NEWS

  5. Log in to comment