On Tue, 30 Jan 2024 at 19:27, Enrico Forestieri <for...@lyx.org> wrote:

> On Sun, Jan 28, 2024 at 12:59:12AM +0100, Enrico Forestieri wrote:
> >
> >On Sat, Jan 27, 2024 at 10:09:05PM +0000, José Matos wrote:
> >>
> >>On Sat, 2024-01-27 at 20:49 +0100, didiergab...@free.fr wrote:
> >>>20:37:37.977: Exportation en cours...
> >>>20:37:37.993: (buffer-export lyxzip)
> >>>20:37:38.150: python -tt "C:/Users/Didier/AppData/Local/Programs/LyX
> >>>2.4/Resources/scripts/lyxpak.py" "K:/CPGE/PTSI/DS/DS-2023-
> >>>2024/DS3/"/"MWE-PDF preview.lyx"
> >>>20:37:38.375: Traceback (most recent call last):
> >>>20:37:38.376:   File "C:\Users\Didier\AppData\Local\Programs\LyX
> >>>2.4\Resources\scripts\lyxpak.py", line 396, in <module>
> >>>20:37:38.377:     if not argv[0].startswith("-"):
> >>>20:37:38.378:            ^^^^^^^^^^^^^^^^^^^^^^^
> >>>20:37:38.378: TypeError: startswith first arg must be bytes or a
> >>>tuple of bytes, not str
> >>>support\Systemcall.cpp (306): Systemcall: 'python -tt
> >>>"C:/Users/Didier/AppData/Local/Programs/LyX
> >>>2.4/Resources/scripts/lyxpak.py" "K:/CPGE/PTSI/DS/DS-2023-
> >>>2024/DS3/"/"MWE-PDF preview.lyx"' finished with exit code 1
> >>>Error: Conversion du fichier impossible
> >>
> >>The problem here is that argv members are of type bytes instead of
> >>being str (string).
> >>
> >>This comes from the fact that the lyxpak.py script has special code to
> >>deal with Python 2 on Windows.
> >>
> >>@Enrico could it be that most of the specific windows code is not need
> >>any more with Python 3?
> >
> >I don't know (I don't use the native windows version). However,
> >skipping that code when using Python3 the script fails as follows:
> >
> >python -tt "C:/Program Files/LyX/Resources/scripts/lyxpak.py"
> "C:/work/"/"a.lyx"
> >Traceback (most recent call last):
> >  File "C:\Program Files\LyX\Resources\scripts\lyxpak.py", line 401, in
> <module>
> >    main(sys.argv)
> >  File "C:\Program Files\LyX\Resources\scripts\lyxpak.py", line 302, in
> main
> >    input = gzopen(lyxfile)
> >            ^^^^^^^^^^^^^^^
> >  File "C:\Program Files\LyX\Resources\scripts\lyxpak.py", line 77, in
> gzopen
> >    input = open(file.decode('utf-8'), 'rb')
> >                 ^^^^^^^^^^^
> >AttributeError: 'str' object has no attribute 'decode'. Did you mean:
> 'encode'?
> >
> >
> >I don't think it was ever tested on Windows with Python3.
>
> For making it work with Python 3 on Windows I had to patch both our
> lyxpak.py script and getopt.py from Python.
>
> Attached you will find the patch to be applied to lyxpak.py, the patch I
> had to apply to getopt.py and the patched version (lyxwin_getopt.py)
> that should be distributed with LyX.
>
> In this way lyxpak.py works for me with both Python 2 and 3, in both
> Windows and Linux.
>
> Please test, especially on Windows.
>

It's going to be a bit hard to test the patch for getopt.py, as the default
LyX installer ships the Python libraries in a .zip file ("C:\Program
Files\LyX 2.4\Python\python311.zip") containing only .pyc files (like
getopt.pyc).

Nevertheless, copying your module lyxwin_getopt and patching lyxpak.py
solves the problem for me! (Windows 11 x64 23H2.)
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to