pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

Invalid escape sequences in python3.py

Open AndrewSwann opened this issue 1 year ago • 3 comments

When compiling a file with pythontex I get messages about invalid escape sequences in python3.py. I am running the latest version from texlive. The output of pythontex --version gives

/usr/local/texlive/2023/texmf-dist/scripts/pythontex/pythontex3.py:549: SyntaxWarning: invalid escape sequence '\s'
  msg = '''
/usr/local/texlive/2023/texmf-dist/scripts/pythontex/pythontex3.py:1810: SyntaxWarning: invalid escape sequence '\s'
  errgobble = match('(\s*)', line).groups()[0]
/usr/local/texlive/2023/texmf-dist/scripts/pythontex/pythontex3.py:2075: SyntaxWarning: invalid escape sequence '\s'
  errgobble = match('(\s*)', line).groups()[0]
PythonTeX 0.18

which already contains the errors.

The first instance should replace "\setpythontexworkingdir{<outputdir>}". by "\\setpythontexworkingdir{<outputdir>}". in the subsequent string. The other two cases should probably replace '(\s*)' by a raw string r'(\s*)'.

I don't have experience of making changes on github, and have not be able to run pythontex in a way that uses a modified local version of python3.py, so have not be able to test these changes.

AndrewSwann avatar Jan 15 '24 13:01 AndrewSwann

I can confirm the issue, but I also get another interesting bit.

/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py:549: SyntaxWarning: invalid escape sequence '\s'
  msg = '''
/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py:1810: SyntaxWarning: invalid escape sequence '\s'
  errgobble = match('(\s*)', line).groups()[0]
/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py:2075: SyntaxWarning: invalid escape sequence '\s'
  errgobble = match('(\s*)', line).groups()[0]
Traceback (most recent call last):
  File "/Library/TeX/texbin/pythontex", line 55, in <module>
    import pythontex3 as pythontex
  File "/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py", line 61, in <module>
    from pygments.styles import get_all_styles
ModuleNotFoundError: No module named 'pygments'

eg9 avatar Aug 04 '24 08:08 eg9

made a pull request. Seems as if some prefix r missing.

Reissner avatar Mar 15 '25 11:03 Reissner

By the way, seems to be a problem only from 3.12 or that like on.

Reissner avatar Mar 15 '25 11:03 Reissner

This is fixed in the development version on GitHub and in the upcoming v0.19 release.

gpoore avatar Nov 11 '25 21:11 gpoore