<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 12 Feb 2021 at 15:50, Thibaut Cuvelier <<a href="mailto:tcuvelier@lyx.org">tcuvelier@lyx.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 12 Feb 2021 at 14:36, Thibaut Cuvelier <<a href="mailto:tcuvelier@lyx.org" target="_blank">tcuvelier@lyx.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 12 Feb 2021 at 06:46, Richard Kimberly Heck <<a href="mailto:rikiheck@lyx.org" target="_blank">rikiheck@lyx.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <div>On 2/11/21 11:19 PM, Thibaut Cuvelier
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Thu, 11 Feb 2021 at
            20:52, Thibaut Cuvelier <<a href="mailto:tcuvelier@lyx.org" target="_blank">tcuvelier@lyx.org</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div dir="ltr">
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Thu, 11 Feb 2021 at
                  20:05, José Abílio Matos <<a href="mailto:jamatos@lyx.org" target="_blank">jamatos@lyx.org</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thursday,
                  February 11, 2021 4:02:19 PM WET Yu Jin wrote:<br>
                  > Will be pointless imo, it's not the script's
                  fault that python is not found.<br>
                  > The fault is to be searched in the part of code
                  which adds the prefix path<br>
                  > to the environment, which part would that be?
                  After all when installing,<br>
                  > the installer adds the prefix path to its
                  environment too on runtime while<br>
                  > installing and then calls the script, it is
                  successful then.<br>
                  <br>
                  Does Tools->Reconfigure works after adding the
                  python path in the environment <br>
                  variable?<br>
                  <br>
                  I expect it to work. If it works that means that the
                  configure.py changes are <br>
                  not the culprit.<br>
                </blockquote>
                <div><br>
                </div>
                <div>In my case, LyX can reconfigure once its PATH
                  includes Python. <br>
                </div>
              </div>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>I just checked that the situation is quite weird: in
            Tools > Preferences > Paths, I have "C:\Program
            Files\MiKTeX
2.9\miktex\bin\x64;$LyXDir\bin;$LyXDir\Python;$LyXDir\Python\Lib;$LyXDir\imagemagick;$LyXDir\ghostscript\bin",
            meaning that LyX should really consider its built-in version
            of Python, but (re)configure always fails if Python is not
            in the environment variable PATH does not contain Python
            before LyX starts. <br>
          </div>
        </div>
      </div>
    </blockquote>
    <p>Does it fail if you try to reconfigure once LyX has launched? If so, can you please open View> Messages, then activate "Files Used By LyX", and reconfigure? I see, at the top
</p>
    <p style="margin:0px;text-indent:0px">00:43:30.779: python3 -tt "/usr/local/share/lyx/configure.py" --binary-dir="/usr/local/bin/"</p>
    <p style="margin:0px;text-indent:0px">
</p>
    <p style="margin:0px;text-indent:0px">That is the command LyX is using to try to reconfigure.</p>
    <p style="margin:0px;text-indent:0px">
Maybe we need also to check what the environment is at that point?</p></div></blockquote><div><br></div><div> Here is what I get (a full LyX session with two calls to reconfigure): <br></div><div><br></div><div>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:30:52.923: Running configure...</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:30:56.919: python -tt "C:/Program Files/LyX 2.4/Resources/configure.py" --binary-dir="C:/Program Files/LyX 2.4/bin/"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:30:57.187: Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:30:57.187: Reloading configuration...Manually looking for python in PATH ...</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Examining "C:/Program Files/MiKTeX 2.9/miktex/bin/x64/pythontex.exe"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Examining "C:/Users/Thibaut/AppData/Local/Microsoft/WindowsApps/python.exe"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Examining "C:/Users/Thibaut/AppData/Local/Microsoft/WindowsApps/python3.exe"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Examining "C:/Users/Thibaut/AppData/Local/Microsoft/WindowsApps/python.exe"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Examining "C:/Users/Thibaut/AppData/Local/Microsoft/WindowsApps/python3.exe"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">Warning: No python v2.x or 3.x binary found.</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">LyX: reconfiguring user directory</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">support\Systemcall.cpp (291): Systemcall: 'python -tt "C:/Program Files/LyX 2.4/Resources/configure.py" --binary-dir="C:/Program Files/LyX 2.4/bin/"' finished with exit code 9009</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">LyX: Done!</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:06.641: (reconfigure)</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:21.627: Running configure...</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:21.766: python -tt "C:/Program Files/LyX 2.4/Resources/configure.py" --binary-dir="C:/Program Files/LyX 2.4/bin/"</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:22.099: Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:22.103: Reloading configuration...LyX: reconfiguring user directory</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">support\Systemcall.cpp (291): Systemcall: 'python -tt "C:/Program Files/LyX 2.4/Resources/configure.py" --binary-dir="C:/Program Files/LyX 2.4/bin/"' finished with exit code 9009</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">LyX: Done!</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:31:23.273: (reconfigure)</p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">14:32:30.743: (dialog-toggle progress)</p></blockquote>




















<p style="margin:0px;text-indent:0px;white-space:pre-wrap"><br></p><p style="margin:0px;text-indent:0px;white-space:pre-wrap">It really seems like LyX is getting the "standard" python.exe that just shows a message and returns an error instead of its own Python (or any other one from the path).<br></p></div></div></div></blockquote><div><br></div><div>I can still reproduce the problem with master: the major difference is that I can use a debugger on that build. Digging in the call stack, it looks like the PATH environment variable is filled with strange things: the letter e is being replaced by $ for the part that LyX prepends! In environment.cpp, getEnv("PATH") returns the following string (truncated), when called from Tools > Reconfigure (find_python_binary in os.cpp): <br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>"C:\\Program Fil$s\\MiKT$X 2.9\\mikt$x\\bin\\x64;D:\\Thibaut\\LyX\\cmak$-build-d$bug-visual-studio\\bin;D:\\Thibaut\\LyX\\cmak$-build-d$bug-visual-studio\\Python;D:\\Thibaut\\LyX\\cmak$-build-d$bug-visual-studio\\Python\\Lib;D:\\Thibaut\\LyX\\cmak$-build-d$bug-visual-studio\\imag$magick;D:\\Thibaut\\LyX\\cmak$-build-d$bug-visual-studio\\ghostscript\\bin;C:\\Program Files\\Common Files\\Oracle\\Java\\javapath;C:\\gurobi911\\win64\\bin;C:\\Program Files\\IBM\\ILOG\\CPLEX_Studio201\\opl\\bin\\x64_win64 […]<br></div></blockquote><div><br></div><div>Only the folders that LyX prepends have Es replaced. In a normal shell or other programs run in my debugger, there is no such thing. <br></div><div><br></div><div>Digging more into it, the first call to getEnv("PATH") returns a perfectly normal value, when called from prependEnvPath in environment.cpp. It's the loop in prependEnvPath that does garbage. In my LyX folder in my user folder, the preferences file has the right line for the path prefix: <br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>\path_prefix "C:/Program Files/MiKTeX 2.9/miktex/bin/x64;$LyXDir/bin;$LyXDir/Python;$LyXDir/Python/Lib;$LyXDir/imagemagick;$LyXDir/ghostscript/bin"</div></blockquote><div><br></div><div>I therefore suspect that replaceEnvironmentPath in filetools.cpp is the source of the problem. <br></div><div><ul><li>I believe this function is wrong on Windows, as environment variables are supposed to be wrapped in %, like %PATH% (and, by the way, environment-variable names are case-insensitive on Windows). (! is only used in Batch files, this symbol should not be interpreted here.) Only the paths that are understood by LyX are transformed (like LyXDir), not all environment variables. Some software adds itself to the path using environment variables, i.e. add something like "%CUDA_PATH%" in the PATH environment variable that just refers to the CUDA_PATH environment variable (set to some perfectly valid path).<br></li><li>The line subst(result, '\e', '$') is the most likely culprit for this error. Maybe some difference in implementation for regexes? <br></li></ul></div></div></div></blockquote><div>Actually, it looks like \e is a GCC-only extension that is not well-understood by MSVC. The attached patch solves the problem for me by replacing \e by another nonprintable character. <br></div></div></div>