Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package minted Error: minted v3+ executable is not installed or is not added to PATH. #401

Open
projetmbc opened this issue Sep 24, 2024 · 37 comments

Comments

@projetmbc
Copy link

projetmbc commented Sep 24, 2024

The following code doesn't compile.

\documentclass[12pt]{article}

\usepackage{minted}

\begin{document}

\begin{minted}{ruby} 
class Foo
    def init
        pi = Math::PI
        @var = "Pi = #{pi}..."
    end 
end
\end{minted}

\end{document}

But I can do :

> python
Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:45:13) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import latexminted
>>> quit()

> which python
/Users/XXXX/opt/anaconda3/bin/python
@gpoore
Copy link
Owner

gpoore commented Sep 24, 2024

Did you just update using CTAN? I believe that there was an issue with the way that CTAN packaged the files for the new release, and they are in the process of fixing it. As a quick fix for the moment, you can probably \usepackage{minted2}, which will use v2.9.

@projetmbc
Copy link
Author

projetmbc commented Sep 24, 2024

I use TeX Live.

The problem is that I work with the tcolorbox library minted. I will wait for a fix. I can do the beta tester.

@yves-chevallier
Copy link

Same issue here. I am using a Docker image here a repeatable example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{minted}

\begin{document}

\begin{minted}{python}
def foo():
    return 1
\end{minted}

\end{document}

I tried with and without the commented lines:

FROM kjarosh/latex:2024.2-basic

RUN tlmgr update --self --all
RUN tlmgr install latexmk fontspec minted latex2pydata pgfopts

#RUN apk add --no-cache py3-pygments py3-pip
#RUN pip install latexminted latexrestricted latex2pydata Pygments --break-system-packages

RUN mkdir -p /tmp/texmf-cache
ENV TEXMFCACHE=/tmp/texmf-cache
ENV TERM=xterm
RUN chmod -R 777 /tmp/texmf-cache

The issue is :

)sh: latexminted: not found

! Package minted Error: minted v3+ executable is not installed or is not added 
to PATH.

@gpoore
Copy link
Owner

gpoore commented Sep 24, 2024

@yves-chevallier Can you post a complete log? When you pip install latexminted, is that successfully creating a latexminted executable on PATH? Right now, tlmgr install minted isn't working for the Python side of things because it omits the Python libraries and doesn't configure a Python executable.

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 25, 2024

Tested on macOS 14.6.1, I can confirm that pip3 install --break-system-packages latexminted (I have python3 installed by Homebrew) did create a latexminted executable in /usr/local/bin, which is contained in PATH.

And after manually installing latex2pydata, the example given in #401 (comment) compiles for me.

@yves-chevallier
Copy link

\documentclass{article}
\usepackage{fontspec}
\usepackage{minted}

\begin{document}

\begin{minted}{python}
def foo():
    return 1
\end{minted}

\end{document}
/workspace # tlmgr install minted upquote lineno
tlmgr: package repository https://texlive.info/CTAN/systems/texlive/tlnet (verified)
[1/13, ??:??/??:??] install: catchfile [3k]
[2/13, 00:00/00:00] install: etoolbox [9k]
[3/13, 00:00/00:00] install: fancyvrb [12k]
[4/13, 00:00/00:00] install: float [3k]
[5/13, 00:00/00:00] install: fp [19k]
[6/13, 00:00/00:00] install: fvextra [15k]
[7/13, 00:01/00:34] install: latex2pydata [4k]
[8/13, 00:01/00:32] install: minted.x86_64-linuxmusl [1k]
[9/13, 00:01/00:32] install: minted [1237k]
[10/13, 00:01/00:01] install: newfloat [7k]
[11/13, 00:01/00:01] install: pgf [701k]
[12/13, 00:02/00:02] install: pgfopts [2k]
[13/13, 00:02/00:02] install: xcolor [18k]
running mktexlsr ...
done running mktexlsr.
tlmgr: package log updated: /opt/texlive/texmf-var/web2c/tlmgr.log
tlmgr: command log updated: /opt/texlive/texmf-var/web2c/tlmgr-commands.log

/workspace # ls /opt/texlive/texmf-dist/tex/latex/minted/minted
minted.sty   minted1.sty  minted2.sty

/workspace # find /opt/texlive/ -iname '*minted*'
/opt/texlive/texmf-dist/scripts/minted
/opt/texlive/texmf-dist/scripts/minted/latexminted-0.1.0-py3-none-any.whl
/opt/texlive/texmf-dist/scripts/minted/latexminted.py
/opt/texlive/texmf-dist/tex/latex/minted
/opt/texlive/texmf-dist/tex/latex/minted/minted2.sty
/opt/texlive/texmf-dist/tex/latex/minted/minted1.sty
/opt/texlive/texmf-dist/tex/latex/minted/minted.sty
/opt/texlive/bin/x86_64-linuxmusl/latexminted
/opt/texlive/tlpkg/tlpobj/minted.tlpobj
/opt/texlive/tlpkg/tlpobj/minted.x86_64-linuxmusl.tlpobj

/workspace # which latexminted
/opt/texlive/bin/x86_64-linuxmusl/latexminted
/workspace # 

/workspace # ls /opt/texlive/texmf-dist/scripts/minted
latex2pydata-0.4.0-py3-none-any.whl     latexminted.py                          pygments-2.18.0-py3-none-any.whl
latexminted-0.1.0-py3-none-any.whl      latexrestricted-0.4.0-py3-none-any.whl

/workspace # latexminted --version
latexminted 0.1.0 (libraries: latex2pydata 0.4.0, pygments 2.18.0)

@yves-chevallier
Copy link

Did you just update using CTAN? I believe that there was an issue with the way that CTAN packaged the files for the new release, and they are in the process of fixing it. As a quick fix for the moment, you can probably \usepackage{minted2}, which will use v2.9.

Using \usepackage{minted2} does not work in the case of other packages that require minted. tcolorbox for instance has a RequirePackage{minted}

@projetmbc
Copy link
Author

Maybe some testing using l3build should be done in such situation breaking API.

@projetmbc
Copy link
Author

Tested on macOS 14.6.1, I can confirm that pip3 install --break-system-packages latexminted (I have python3 installed by Homebrew) did create a latexminted executable in /usr/local/bin, which is contained in PATH.

And after manually installing latex2pydata, the example given in #401 (comment) compiles for me.

The problem is that I've created a package that needs minted. At the moment, my package is broken. This isn't a problem, as I must be the only person to use this package, but it's more problematic in the case of tcolorbox.

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 25, 2024

Using \usepackage{minted2} does not work in the case of other packages that require minted. tcolorbox for instance has a RequirePackage{minted}

It should work fine if minted2 is loaded before any \RequirePackage{minted}. That's because minted2 acts as if minted v2.9 is being loaded, not a package named minted2. See T-F-S/tcolorbox#2 (comment) for more info.

\documentclass{article}
\usepackage{minted2}
\usepackage{minted}

\begin{document}
\UseName{ver@minted.sty} % "2023/12/18 v2.9"
\end{document}

@projetmbc
Copy link
Author

projetmbc commented Sep 25, 2024

Thanks a lot for this patch for tcolorbox. I will update my only-one-user CTAN package soon. :-)

\RequirePackage{minted2}

\RequirePackage{tcolorbox}%
               [2024/07/10]

\tcbuselibrary{minted, breakable, skins}

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 25, 2024

The trick described in my last comment #401 (comment) works for all existing documents in which minted were loaded by one of \usepackage, \RequirePackage, and \RequirePackageWithOptions, not just the tcolorbox case. And it's provided by minted.

But there's a limitation: minted options set by \PassOptionsToPackage{<option list>}{minted} is not used by \usepackage{minted2}. For example try with \PassOptionsToPackage{draft}{minted}.

In other words, to pass options to minted2, you have to write \PassOptionsToPackage{<option list>}{minted2} rather than \PassOptionsToPackage{<option list>}{minted}.

@gpoore
Copy link
Owner

gpoore commented Sep 25, 2024

CTAN has repackaged minted, so tlmgr install minted should now work correctly and install the Python executable with libraries. (It might still be a few hours before the changes get to all servers, but it worked for me several hours ago, and then again just now.) I suppose it might be good to do tlmgr uninstall minted first. Also, TeX Live has now added latexminted to the trusted executable list, so -shell-escape is no longer required.

@projetmbc
Copy link
Author

projetmbc commented Sep 25, 2024

This almost works but the first compilation raises one error. No extra file exists at the time of the first compilation... The 2nd compilation is fined but very slow.

./listing-direct.tex:118: Package minted Error: 
 => ./listing-direct:56: Cannot find the correct input file "listing-direct.lis
ting"; there may be multiple files with the same name, or the file may have bee
n modified during compilation.

OS: MacOS
Distrib. MacTeX

@gpoore
Copy link
Owner

gpoore commented Sep 25, 2024

@projetmbc To avoid that error, you probably need \usepackage[highlightmode=immediate]{minted}. Version 3 attempts to speed up highlighting by performing all highlighting at the very end of a file when a file is compiled for the very first time, and then switches to highlighting immediately on subsequent compiles. But that doesn't work when temp files are being highlighted, since they keep getting modified or deleted during compilation. I may need to modify the optimization process to try to detect things like tcolorbox temp files.

Witiko added a commit to Witiko/markdown that referenced this issue Sep 30, 2024
Minted 3.0 currently has issue with the distribution, see
<gpoore/minted#401>.
Witiko added a commit to Witiko/markdown that referenced this issue Sep 30, 2024
Minted 3.0 currently has issue with the distribution, see
<gpoore/minted#401>.
Witiko added a commit to Witiko/markdown that referenced this issue Sep 30, 2024
Minted 3.0 currently has issue with the distribution, see
<gpoore/minted#401>.
Witiko added a commit to Witiko/markdown that referenced this issue Sep 30, 2024
Minted 3.0 currently has issue with the distribution, see
<gpoore/minted#401>.
gpoore added a commit that referenced this issue Oct 2, 2024
…ally detected and processed correctly regardless of highlightmode (#401)
@lstngr
Copy link

lstngr commented Oct 3, 2024

I got this error on Leap 15.6 today. It turns out that the Python interpreter is quite old (3.6) and while latexminted is in my PATH, it fails to execute. (One can work around it with a venv since latexminted relies on /usr/bin/env to find the python3 executable).

@muzimuzhi
Copy link
Contributor

FYI, from its config and doc, latexminted v0.1.0 requires Python 3.8 or newer.

Source snippets

requires-python = '>= 3.8'

1. The libraries used by the `latexminted` executable require Python >= 3.8.
If the default Python version is < 3.8, then `latexminted` will attempt to
locate a more recent Python installation and run itself with that Python
version in a subprocess. Python's `shutil.which()` is used to search
`PATH` for more recent Python versions.

@lstngr
Copy link

lstngr commented Oct 3, 2024

Thanks @muzimuzhi, indeed. I was mostly making the (unclear, I realize!) point that the error doesn't pinpoint the failure correctly and might be confusing to some users. Cheers!

@projetmbc
Copy link
Author

The last version works fine. Is it easy to explain the fixes done?

@gpoore
Copy link
Owner

gpoore commented Oct 5, 2024

@projetmbc The issues were probably due to #405. Basically, under some configurations, the timestamps and perhaps some other data sent from Python back to LaTeX needed \detokenize to guarantee that they were processed correctly.

@gpoore
Copy link
Owner

gpoore commented Oct 13, 2024

@yves-chevallier Are you still having any issues, using the latest minted v3.1.2 plus latexminted v0.2.0? I believe things are now working for everyone else who commented on this issue.

@HolgerHuo
Copy link

Hi! I'm also facing this issue when building a texlive docker image for overleaf. Currently we install package minted in this way:

mkdir /install-tl-unx \
&&  wget --quiet https://tug.org/texlive/files/texlive.asc \
&&  gpg --import texlive.asc \
&&  rm texlive.asc \
&&  wget --quiet ${TEXLIVE_MIRROR}/install-tl-unx.tar.gz \
&&  wget --quiet ${TEXLIVE_MIRROR}/install-tl-unx.tar.gz.sha512 \
&&  wget --quiet ${TEXLIVE_MIRROR}/install-tl-unx.tar.gz.sha512.asc \
&&  gpg --verify install-tl-unx.tar.gz.sha512.asc \
&&  sha512sum -c install-tl-unx.tar.gz.sha512 \
&&  tar -xz -C /install-tl-unx --strip-components=1 -f install-tl-unx.tar.gz \
&&  rm install-tl-unx.tar.gz* \
&&  echo "tlpdbopt_autobackup 0" >> /install-tl-unx/texlive.profile \
&&  echo "tlpdbopt_install_docfiles 0" >> /install-tl-unx/texlive.profile \
&&  echo "tlpdbopt_install_srcfiles 0" >> /install-tl-unx/texlive.profile \
&&  echo "selected_scheme scheme-full" >> /install-tl-unx/texlive.profile \
&&  echo "tlpdbopt_sys_bin /usr/bin" >> /install-tl-unx/texlive.profile \
    \
&&  /install-tl-unx/install-tl \
      -profile /install-tl-unx/texlive.profile \
      -repository ${TEXLIVE_MIRROR} \
    \
&&  $(find /usr/local/texlive -name tlmgr) path add \
&&  rm -rf /install-tl-unx

And when compiling, it shows:

Package minted Error: minted v3+ executable is not installed or is not added to PATH.

I can confirm that python, python3, pygmentize, latexminted are all in my path, and i have python3 > 3.11, latexminted==2.11 (lower than latest, but upgrading doesnt help), and minted from ctan = 3.1.2.

I seem to have run out of ways to debug.

@gpoore
Copy link
Owner

gpoore commented Oct 17, 2024

@HolgerHuo You might try compiling a simple document like this, using the new debug package option:

\documentclass{article}
\usepackage[debug]{minted}
\begin{document}

X\mintinline{python}{"x"}X

\end{document}

If there is some sort of unexpected, uncaught error, it might appear in the *.minted temp files that are kept with debug, especially if there is an *.errlog.minted file. If you don't see something obvious in the *.minted files, you could post them here so I can take a look.

At this point, I believe that the issues that others initially had with Docker images with minted v3.0.0 have been resolved, so it's possible this is something new or different.

@HolgerHuo
Copy link

@gpoore The output shows latexminted.err.LatexMintedConfigError: Permission error prevented access to config file "/tmp/.latexminted_config" and it seems to be a permission issue on my side. I'll try fix it. Thank you so much for your great help!

@andreondra
Copy link

andreondra commented Oct 18, 2024

It still does not work in Overleaf Community. I opened an issue there, it is probably caused by something specific in the Docker installation.

It works by upgrading latexminted manually via pip3. Is this OK approach or packages should be already installed automatically by tlmgr?

@gpoore
Copy link
Owner

gpoore commented Oct 18, 2024

@andreondra When tlmgr updates the minted package, that should include the latest version of latexminted and all other Python libraries, installing them within TeX Live. Does Overleaf Community use packages directly from CTAN, or is some sort of intermediate package repository involved, which might cause a time delay in getting the latest packages?

In most cases, upgrading latexminted manually should work, but that may occasionally cause errors if the LaTeX side of things gets too far behind the Python side. This is also part of the reason for bundling everything in TeX Live.

@andreondra
Copy link

I think it uses standard TeXLive installation. I am able to install/update packages via tlmgr and see the minted is the latest version. I'd say that the problem is something with incorrect PATH, because I can actually see latexminted installed in the TeXLive directory, but the system one takes precedence. I'll keep the manually upgraded latexminted for now and see if someone responds in the Overleaf repo.

Thank you for now!

@HolgerHuo
Copy link

@andreondra Hi, I'm also having this issue with overleaf's sharelatex-base image. From my observations, this issues is due to insufficient access to /tmp directory. I haven't figured out how to solve it though.

@gpoore
Copy link
Owner

gpoore commented Oct 19, 2024

@HolgerHuo latexminted looks for .latexminted_config config files in HOME (from Python's pathlib.Path.home()), TEXMFHOME (from kpsewhich), and the current working directory. These should all be readable locations. However, it looks like one of these corresponds to an unreadable /tmp in the image you are working with. That may be an issue with the image configuration. I may also need to consider modifying latexminted so that it ignores permission errors in locating the config files.

@HolgerHuo
Copy link

HolgerHuo commented Oct 19, 2024

@gpoore Wow, thanks a lot for providing that information. Overleaf do passes HOME=/tmp environment into the container, so latexminted does need to read/write files into that directory. I just haven't figured out why it doesn't have access to /tmp, considering it is just a tmp directory.

Weird things are that when i manually started a test container using same configuration as overleaf did, everything worked. These issues are not related to minted package anyway.

@andrew-selvia
Copy link

andrew-selvia commented Oct 27, 2024

I'm afraid I'm encountering the same issue:

Package minted Error: minted v3+ executable is not installed, is not added to PATH, or is not permitted with restricted shell escape.

I've installed latexminted:

pip install latexminted --break-system-packages

latexminted --version output:

% latexminted --version
latexminted 0.2.0
Python executable for the LaTeX minted package
Libraries: latex2pydata 0.4.0, latexrestricted 0.5.0, pygments 2.18.0
Repository: https://github.com/gpoore/minted
CTAN: https://ctan.org/pkg/minted
PyPI: https://pypi.org/project/latexminted

I also installed the minted package via MiKTeX:

% mpm --list-package-names | grep minted
minted
minted__doc
minted__source

I'm compiling my document with pdflatex on macOS 15.0.1 (Sequoia). The document did not use minted previously; I just discovered it and am trying to integrate it. The document compiles successfully without the minted portion. I've started with the same bare-bones example shared in the initial post.

Assuming I haven't missed anything obvious, what else should I provide to help debug further?

Updates

I've just discovered this in the log file; perhaps that gives a better clue:

runsystem(latexminted config  --timestamp 20241027000904 FAD58DE7366495DB4650CF
EFAC2FCD61)...disabled (restricted).

Adding either of these flags to pdflatex:

-shell-escape -enable-write18

results in the following error during compilation:

[error] Traceback (most recent call last):
[error]   File ".../venv/lib/python3.13/site-packages/latexrestricted/_restricted_pathlib.py", line 647, in writable_file
[error]     return self._writable_file_cache[self.cache_key]
[error]            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
[error] KeyError: (<class 'latexrestricted._restricted_pathlib.ResolvedRestrictedPath'>, ResolvedRestrictedPath('/Users/me/.latexminted_config'))
[error] During handling of the above exception, another exception occurred:
...
[error] latexrestricted.err.LatexConfigError: Environment variable TEXSYSTEM="miktex", but failed to find an "initexmf" executable with accompanying "kpsewhich" on PATH

I've given all permissions to latexminted (i.e., chmod 777 .../latexminted), but still see the same errors. Hitting a wall. 🥺

@muzimuzhi
Copy link
Contributor

@andrew-selvia The first part of your problems looks like a MiKTeX issue, see MiKTeX/miktex#1538 (comment). Sorry I have no idea about the second part.

@gpoore
Copy link
Owner

gpoore commented Oct 29, 2024

@andrew-selvia Do you have a kpsewhich executable as part of your MiKTeX installation, and if so is it on PATH? If for some reason MiKTeX isn't including its own kpsewhich executable under macOS (and perhaps some other operating system), then I will need to rewrite parts of latexrestricted that rely on kpsewhich.

@andrew-selvia
Copy link

@gpoore They appear to be present on the PATH:

% which kpsewhich
~/bin/kpsewhich
% which initexmf
~/bin/initexmf
% which miktex
~/bin/miktex

I did briefly attempt to drill into latexrestricted but made no meaningful headway. Anything else you'd like me to provide?

gpoore added a commit to gpoore/latexrestricted that referenced this issue Oct 29, 2024
@gpoore
Copy link
Owner

gpoore commented Oct 29, 2024

@andrew-selvia Under macOS, kpsewhich is apparently a symlink to miktex-kpsewhich. I've just released latexrestricted v0.6.0, which adds support for miktex-kpsewhich. If you upgrade latexrestricted with pip, that should fix things.

@andrew-selvia
Copy link

andrew-selvia commented Oct 30, 2024

@gpoore It does resolve the first issue:

runsystem(latexminted config  --timestamp 20241030113915 FAD58DE7366495DB4650CF
EFAC2FCD61)...**executed**.

The document continues to report errors upon compilation, unfortunately.

I have tried running that command manually, but it results in a new error:

% latexminted config  --timestamp 20241030113915 FAD58DE7366495DB4650CF
EFAC2FCD61
Traceback (most recent call last):
  File ".../latexrestricted/_restricted_pathlib.py", line 641, in writable_file
    return self._writable_file_cache[self.cache_key]
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: (<class 'latexrestricted._restricted_pathlib.ResolvedRestrictedPath'>, ResolvedRestrictedPath('~/.latexminted_config'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
...
latexrestricted.err.LatexConfigError: Environment variable SELFAUTOLOC is expected for TeX Live, but was not set

And for sanity, I can confirm latexrestricted 0.6.0 has been picked up properly:

% latexminted --version
latexminted 0.3.0
Python executable for the LaTeX minted package
Libraries: latex2pydata 0.4.0, latexrestricted 0.6.0, pygments 2.18.0

If you'd prefer to track this separately, I'll create a new issue. It's unclear to me whether it's related to the original one.

@gpoore
Copy link
Owner

gpoore commented Oct 30, 2024

@andrew-selvia Go ahead and create a new issue...this is probably no longer related to the original one. If you can post a compilation log and any .errlog.minted file, that would be helpful. latexminted can only be run manually if you set the expected environment variables; for MiKTeX, that means setting TEXSYSTEM to "miktex".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants