Skip to content

Local variable "sitedir" is not defined since Python 3.15.0-beta.1 #14426

Description

@FriedrichFroebel

Describe the bug

GitHub Actions just switched from Python 3.15.0-alpha.8 to 3.15.0-beta.1 and I am receiving the following error when running sphinx-build -W -b doctest doc/api/ tmp or nearly all other commands:

Error in import line from /opt/hostedtoolcache/Python/3.15.0-beta.1/x64/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
  Traceback (most recent call last):
    File "<frozen site>", line 319, in _exec_imports
    File "<string>", line 1, in <module>
  KeyError: "local variable ''sitedir'' is not defined"

How to Reproduce

Install sphinx and run anything importing Python modules, like the Sphinx build, flake8, tests etc.

Environment Information

Successfully installed Jinja2-3.1.6 MarkupSafe-3.0.3 Pygments-2.20.0 alabaster-1.0.0 babel-2.18.0 certifi-2026.4.22 charset_normalizer-3.4.7 djvulibre-python-0.9.3 docutils-0.22.4 flake8-7.3.0 idna-3.13 imagesize-1.5.0 mccabe-0.7.0 numpy-2.4.4 pep8-naming-0.15.1 pycairo-1.29.0 pycodestyle-2.14.0 pyflakes-3.4.0 requests-2.33.1 roman-numerals-4.1.0 snowballstemmer-3.0.1 sphinx-9.1.0 sphinxcontrib-applehelp-2.0.0 sphinxcontrib-devhelp-2.0.0 sphinxcontrib-htmlhelp-2.1.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-2.0.0 sphinxcontrib-serializinghtml-2.0.0 urllib3-2.7.0

Sphinx extensions

Additional context

No response

Activity

  1. hugovk commented on May 10, 2026

    @hugovk
    Contributor

    First of all, thank you for testing the 3.15 pre-releases and reporting this bug!

    Also reproducible with CPython docs:

    Details
    ❯ make -C Doc clean venv html PYTHON=3.15
    rm -rf ./venv
    rm -rf build/*
    Creating venv in ./venv
    Using CPython 3.15.0b1 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
    Creating virtual environment at: ./venv
    Activate with: source venv/bin/activate
    warning: The `--pylock` option is experimental and may change without warning. Pass `--preview-features pylock` to disable this warning.
    Using Python 3.15.0b1 environment at: venv
    Prepared 28 packages in 6ms
    Installed 28 packages in 91ms
     + alabaster==1.0.0
     + babel==2.18.0
     + blurb==2.0.0
     + certifi==2026.4.22
     + charset-normalizer==3.4.7
     + docutils==0.21.2
     + idna==3.13
     + imagesize==1.5.0
     + jinja2==3.1.6
     + linklint==1.0.0
     + markupsafe==2.1.5
     + packaging==24.2
     + pygments==2.20.0
     + python-docs-theme==2026.4
     + requests==2.33.1
     + roman-numerals==4.1.0
     + roman-numerals-py==4.1.0
     + snowballstemmer==2.2.0
     + sphinx==8.2.3
     + sphinx-notfound-page==1.0.4
     + sphinxcontrib-applehelp==2.0.0
     + sphinxcontrib-devhelp==2.0.0
     + sphinxcontrib-htmlhelp==2.1.0
     + sphinxcontrib-jsmath==1.0.1
     + sphinxcontrib-qthelp==2.0.0
     + sphinxcontrib-serializinghtml==2.0.0
     + sphinxext-opengraph==0.13.0
     + urllib3==2.6.3
    The venv has been created in the ./venv directory
    mkdir -p build
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    blurb version 2.0.0
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    sphinx-build 8.2.3
    Building NEWS from Misc/NEWS.d with blurb
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    PATH=./venv/bin:$PATH sphinx-build --builder html --doctree-dir build/doctrees --jobs auto   --fail-on-warning . build/html
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    Error in import line from /Users/hugo/github/python/cpython/main/Doc/venv/lib/python3.15/site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth: import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('sphinxcontrib',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('sphinxcontrib', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('sphinxcontrib', [os.path.dirname(p)])));m = m or sys.modules.setdefault('sphinxcontrib', types.ModuleType('sphinxcontrib'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
      KeyError: "local variable ''sitedir'' is not defined"
    Running Sphinx v8.2.3
    loading translations [en]... done
    matplotlib is not installed, social cards will not be generated
    making output directory... done
    building [mo]: targets for 0 po files that are out of date
    writing output...
    building [html]: targets for 548 source files that are out of date
    updating environment: [new config] 548 added, 0 changed, 0 removed
    reading sources... [100%] whatsnew/changelog .. whatsnew/index
    looking for now-outdated files... none found
    pickling environment... done
    checking consistency... /Users/hugo/github/python/cpython/main/Doc/howto/argparse.rst: document is referenced in multiple toctrees: ['howto/index', 'library/argparse'], selecting: library/argparse <- howto/argparse
    done
    preparing documents... done
    copying assets...
    copying downloadable files... [100%] includes/tzinfo_examples.py
    copying static files...
    Writing evaluated template result to /Users/hugo/github/python/cpython/main/Doc/build/html/_static/basic.css
    Writing evaluated template result to /Users/hugo/github/python/cpython/main/Doc/build/html/_static/language_data.js
    Writing evaluated template result to /Users/hugo/github/python/cpython/main/Doc/build/html/_static/documentation_options.js
    Writing evaluated template result to /Users/hugo/github/python/cpython/main/Doc/build/html/_static/classic.css
    Writing evaluated template result to /Users/hugo/github/python/cpython/main/Doc/build/html/_static/sidebar.js
    copying static files: done
    copying extra files...
    copying extra files: done
    copying assets: done
    writing output... [100%] whatsnew/3.5 .. whatsnew/index
    generating indices... genindex py-modindex done
    writing additional pages... download index search opensearch done
    copying images... [100%] using/win_install_freethreaded.png
    dumping search index in English (code: en)... done
    dumping object inventory... done
    Writing glossary.json
    profiling_trace: Injected 38 trace events into profiling-sampling-visualization.js
    Linklint: unlinked 3584 refs: 2000 duplicate, 1584 self
    build succeeded.
    
    The HTML pages are in build/html.
    
    Build finished. The HTML pages are in build/html.

    Minimal repro:

    ❯ echo "import sys; sys._getframe(1).f_locals['sitedir']" > legacy.pth
    
    ❯ python3.14 -c "import site; site.addsitedir('.')"
    
    ❯ python3.15 -c "import site; site.addsitedir('.')"
    Found existing alias for "python3.15". You should use: "p5"
    Error in import line from /Users/hugo/github/python/cpython/main/legacy.pth: import sys; sys._getframe(1).f_locals['sitedir']
      Traceback (most recent call last):
        File "<frozen site>", line 319, in _exec_imports
        File "<string>", line 1, in <module>
          import site; site.addsitedir('.')
                      ~~~~~~~~~~~~~~~~^^^^^
      KeyError: "local variable ''sitedir'' is not defined"

    Not reproducible in a8, but is in b1.

    Bisects to PEP 829: python/cpython#149109, cc @warsaw.

  2. m-aciek commented on May 10, 2026

    @m-aciek
    Contributor

    Where is this pth file coming from? There's python 3.7 mentioned in its name. The only wheel published for related package (by pth file name) is this: https://pypi.org/project/sphinxcontrib-jsmath/#sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl

  3. hugovk commented on May 11, 2026

    @hugovk
    Contributor
  4. hugovk commented on May 19, 2026

    @hugovk
    Contributor

    Update: closed as won't fix in CPython, instead setuptools will be updated.

    python/cpython#149671 (comment)

    https://github.com/sphinx-doc/sphinxcontrib-jsmath no longer uses setuptools anyway, so we need a new release there.

    (sphinxcontrib-jsmath has no issue tracker, so this issue will have to do.)

  5. SnoopJ commented on Aug 4, 2026

    @SnoopJ

    Sopel experienced this failure downstream when evaluating our 3.15 support (see sopel-irc/sopel#2737) and I can confirm that as of rc1 it is no longer there.

    I think this issue is probably ripe for closure now that CPython has issued a fix, @FriedrichFroebel can you re-test?

  6. FriedrichFroebel commented on Aug 5, 2026

    @FriedrichFroebel
    Author

    As per the above discussions, sphinxcontrib-jsmath should still receive a new release to avoid this issue coming back in the future - at least this is what I remember from the CPython issue discussions.

    While I am the issue author and could in theory close this issue, I will leave the final decision to the maintainers to hopefully fix this on the long term if possible.

  7. jdillard commented on Aug 18, 2026

    @jdillard
    SponsorMember

    I also think this should stay open until sphinxcontrib-jsmath gets a new release.

  8. added
    extensions:mathematicsThe `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15Affects Python 3.15 versionsextensions:mathematicsThe `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensionstype:bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions