I’m try to use the minted
package in latex to display code in latex document. From Texstudio, I get an error message you must have pygmentize installed to use this package
.
If I type pip3 install pygments
I get
Requirement already satisfied: pygments in /usr/local/lib/python3.7/site-packages (2.3.1)
which means that pip3
has installed on the machine.
So after typing pip3 show Pygments
I get the path where that package is installed namely: /usr/local/lib/python3.7/site-packages
. Moreover, when I launch python from the Terminal
and type import pygments
no error message is displayed. That means that it is correctly installed but that the latex editor cannot find it.
What am I doing wrong?
Edit
as pointed in the answers below
I get as the first message:
Package minted Error: You must invoke LaTeX with the -shell-escape flag. begin
only then I get:
Package minted Error: You must have `pygmentize' installed to use this package. begin{document}
Package minted Error: Missing Pygments output; inputminted wasor may be using frozencache with a missing file. end{minted}^^M
Package minted Error: Missing Pygments output; inputminted wasor may be using frozencache with a missing file. end{minted}^^M
Package minted Error: Missing Pygments output; inputminted wasor may be using frozencache with a missing file. end{minted}
shell escape is disabled, so I can only detect ifwindows.
Here is a piece of code:
documentclass[a4paper, 12pt]{book}
usepackage{minted}
begin{document}
chapter{Introduction}
begin{minted}{python}
print("hello world")
end{minted}
end{document}
Edit 2
As pointed out in another answer, the problem seems to be in the configuration option. So after going in «Textstudio > Preferences > Build» I clicked on the Add
button and entered pdflatex -shell-escape
in the left cell and pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex
in the right cell as shown below:
I do get a new command in the User Menu:
I then quit this menu, but the problem persisted.
What am I still missing
Here is the list of the log file:
Here is the printed log file:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.9.16) 23 APR 2019 20:44
entering extended mode
restricted write18 enabled.
%&-line parsing enabled.
**python_latex.tex
(./python_latex.tex
LaTeX2e <2018-04-01> patch level 2
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/bk12.clo
File: bk12.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
c@part=count80
c@chapter=count81
c@section=count82
c@subsection=count83
c@subsubsection=count84
c@paragraph=count85
c@subparagraph=count86
c@figure=count87
c@table=count88
abovecaptionskip=skip41
belowcaptionskip=skip42
bibindent=dimen102
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/minted/minted.sty
Package: minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
KV@toks@=toks14
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
Package etexcmds Info: Could not find expanded.
(etexcmds) That can mean that you are not using pdfTeX 1.50 or
(etexcmds) that some package has redefined expanded.
(etexcmds) In the latter case, load this package earlier.
)))
(/usr/local/texlive/2018/texmf-dist/tex/latex/fvextra/fvextra.sty
Package: fvextra 2017/07/08 v1.3.1 fvextra - extensions and patches for fancyvr
b
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ifthen.sty
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2018/02/11 v2.5e e-TeX tools for LaTeX (JAW)
etb@tempcnta=count89
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Package: fancyvrb 2008/02/07
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix
<2008/02/07> (tvz)
FV@CodeLineNo=count90
FV@InFile=read1
FV@TabBox=box26
c@FancyVerbLine=count91
FV@StepNumber=count92
FV@OutFile=write3
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/upquote/upquote.sty
Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba
tim
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/lineno/lineno.sty
Package: lineno 2005/11/02 line numbers on paragraphs v4.41
linenopenalty=count93
output=toks15
linenoprevgraf=count94
linenumbersep=dimen103
linenumberwidth=dimen104
c@linenumber=count95
c@pagewiselinenumber=count96
c@LN@truepage=count97
c@internallinenumber=count98
c@internallinenumbers=count99
quotelinenumbersep=dimen105
bframerule=dimen106
bframesep=dimen107
bframebox=box27
LaTeX Info: Redefining \ on input line 3056.
)
c@FV@TrueTabGroupLevel=count100
c@FV@TrueTabCounter=count101
FV@TabBox@Group=box28
FV@TmpLength=skip43
c@FV@HighlightLinesStart=count102
c@FV@HighlightLinesStop=count103
FV@LoopCount=count104
FV@NCharsBox=box29
FV@BreakIndent=dimen108
FV@BreakIndentNChars=count105
FV@BreakSymbolSepLeft=dimen109
FV@BreakSymbolSepLeftNChars=count106
FV@BreakSymbolSepRight=dimen110
FV@BreakSymbolSepRightNChars=count107
FV@BreakSymbolIndentLeft=dimen111
FV@BreakSymbolIndentLeftNChars=count108
FV@BreakSymbolIndentRight=dimen112
FV@BreakSymbolIndentRightNChars=count109
c@FancyVerbLineBreakLast=count110
FV@LineBox=box30
FV@LineIndentBox=box31
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/calc.sty
Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
calc@Acount=count111
calc@Bcount=count112
calc@Adimen=dimen113
calc@Bdimen=dimen114
calc@Askip=skip44
calc@Bskip=skip45
LaTeX Info: Redefining setlength on input line 80.
LaTeX Info: Redefining addtolength on input line 81.
calc@Ccount=count113
calc@Cskip=skip46
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/shellesc.sty
Package: shellesc 2016/06/07 v0.02a unified shell escape interface for LaTeX
Package shellesc Info: Restricted shell escape enabled on input line 69.
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/ifplatform/ifplatform.sty
Package: ifplatform 2017/10/13 v0.4a Testing for the operating system
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2017/03/15 v3.2 Provides the ifpdf switch
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: pdf@primitive is available.
Package pdftexcmds Info: pdf@ifprimitive is available.
Package pdftexcmds Info: pdfdraftmode found.
)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/catchfile.sty
Package: catchfile 2016/05/16 v1.7 Catch the contents of a file (HO)
)
Package ifplatform Warning:
shell escape is disabled, so I can only detect ifwindows.
) (/usr/local/texlive/2018/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/xstring/xstring.tex
@xs@message=write4
integerpart=count114
decimalpart=count115
)
Package: xstring 2013/10/13 v1.7c String manipulations (C Tellechea)
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/framed/framed.sty
Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks
OuterFrameSep=skip47
fb@frw=dimen115
fb@frh=dimen116
FrameRule=dimen117
FrameSep=dimen118
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/float/float.sty
Package: float 2001/11/08 v1.3d Float enhancements (AL)
c@float@type=count116
float@exts=toks16
float@box=box32
@float@everytoks=toks17
@floatcapt=box33
)
minted@appexistsfile=read2
minted@bgbox=box34
minted@code=write5
c@minted@FancyVerbLineTemp=count117
c@minted@pygmentizecounter=count118
@float@every@listing=toks18
c@listing=count119
)
runsystem(mkdir -p _minted-python_latex)...disabled (restricted).
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.3 begin
{document}
Pass the -shell-escape flag to LaTeX. Refer to the minted.sty documentation for
more information.
(/usr/local/texlive/2018/texmf-dist/tex/latex/xcolor/xcolor.sty
Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/color.cfg
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package xcolor Info: Driver file: pdftex.def on input line 225.
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/pdftex.def
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
)
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
Package xcolor Info: Model `RGB' extended on input line 1364.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
)
runsystem(which pygmentize && touch python_latex.aex)...disabled (restricted).
! Package minted Error: You must have `pygmentize' installed to use this packag
e.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.3 begin{document}
Refer to the installation instructions in the minted documentation for more inf
ormation.
(./python_latex.aux)
openout1 = `python_latex.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info: ... okay on input line 3.
(/usr/local/texlive/2018/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
scratchcounter=count120
scratchdimen=dimen119
scratchbox=box35
nofMPsegments=count121
nofMParguments=count122
everyMPshowfont=toks19
MPscratchCnt=count123
MPscratchDim=dimen120
MPnumerator=count124
makeMPintoPDFobject=count125
everyMPtoPDFconversion=toks20
)
Chapter 1.
openout3 = `python_latex.pyg'.
runsystem(pygmentize -S default -f latex -P commandprefix=PYG > _minted-python_
latex/default-pyg-prefix.pygstyle)...disabled (restricted).
! Package minted Error: Missing Pygments output; inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.7 end{minted}^^M
This could be caused by using -output-directory or -aux-directory
without setting minted's outputdir, or by using a build tool that
changes paths in ways minted cannot detect,
or using frozencache with a missing file.
runsystem(pygmentize -S default -f latex -P commandprefix=PYGdefault > _minted-
python_latex/default.pygstyle)...disabled (restricted).
! Package minted Error: Missing Pygments output; inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.7 end{minted}^^M
This could be caused by using -output-directory or -aux-directory
without setting minted's outputdir, or by using a build tool that
changes paths in ways minted cannot detect,
or using frozencache with a missing file.
runsystem(pygmentize -l python -f latex -P commandprefix=PYG -F tokenmerge -o _
minted-python_latex/72214DB4E1E543018D1BAFE86EA3B4440B40C301701A64D52CDA79C72DA
628CC.pygtex python_latex.pyg)...disabled (restricted).
! Package minted Error: Missing Pygments output; inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.7 end{minted}
This could be caused by using -output-directory or -aux-directory
without setting minted's outputdir, or by using a build tool that
changes paths in ways minted cannot detect,
or using frozencache with a missing file.
[1
{/usr/local/texlive/2018/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./python_latex.aux)
runsystem(rm python_latex.pyg)...disabled (restricted).
)
Here is how much of TeX's memory you used:
4355 strings out of 492649
78111 string characters out of 6129622
188991 words of memory out of 5000000
8209 multiletter control sequences out of 15000+600000
4544 words of font info for 17 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
37i,5n,35p,843b,142s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb
></usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb>
Output written on python_latex.pdf (1 page, 17712 bytes).
PDF statistics:
16 PDF objects out of 1000 (max. 8388607)
10 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)
ANSWER
As pointed out in the from linked question just insert the following line in the document: % !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
Содержание
- Minted cannot find pygmentize in TexStudio on Windows 7
- 2 Answers 2
- Using “minted” package in Latex to format programming codes on Windows machines
- Minted не может найти пигментирование в TexStudio на Windows 7
- 2 ответа 2
Minted cannot find pygmentize in TexStudio on Windows 7
I want to use minted package, but when I’m xelatexing in TexStudio , there’s an error:
pip seems unable to find pygmentize:
In my C:Python26Scripts there are files named pygmentize :
I have followed instructions from here https://tex.stackexchange.com/questions/108661/how-to-use-minted-under-miktex-and-windows-7 where it is suggested to install Pygments which is what I did:
This is my PATH:
However it is not working. How should I fix this?
2 Answers 2
I had the exact same problem, but on Windows 10. I will now write a proper answer for future users.
There are 3 things that must be done in order to use the minted package in TeX:
Change your pdflatex output to include -shell-escape,
Make sure pygmentize is installed in your python shell, and most difficultly
Make sure TeX prioritizes the correct PATH.
- Go to Options in your preferred TeX editor and change the PdfLaTeX to: whatever it was before and then «-shell-escape %.tex»
- Go to your Python Shell, fx Anaconda Prompt if you’re using Anaconda as your Python editor. Check if pygmentize is already installed by writing: pygmentize -V . If it brings up your current version, continue to solution 3. If not, type: pip install Pygments . This should install pygmentize in whatever folder your Python editor uses for scripts, which is needed for the next solution.
First, use Windows search to find «pygmentize.exe». Copy the path from the address bar, fx «C:UsersYourUsernameHereAnaconda3Scripts».
Now use Windows search to find «Advanced System Settings». Clicking on the result should bring you exactly to the «Advanced» tab of the System Settings, if not, go there. There will be a button for «Environment Variables. «, click on it.
Under the «User variables for YourUsernameHere», click on the variable «Path» and then click «Edit. «. Create a new path for the copied path from earlier, fx «C:UsersYourUsernameHereAnaconda3Scripts», and then click «Move up» until it is above any TeX related paths.
Restart your computer. Minted should now work 🙂
Hope this helps someone in the future save precious time that I wasted myself. Net gain!
Источник
Using “minted” package in Latex to format programming codes on Windows machines
I was looking for a package to format programming code inside document for a specific programming language. There are two popular options, which are minted and listings . Between the two options, I found minted more flexible and easy to use, of course only when installed. It allows you to easily specify the programming language of your interest, to format margins, line spacing, footnoting, reading from an actual code file, and other things. I am a Windows user (unfortunately) and installing minted is not as easy as you might think. I found no comprehensive guidelines to install this package and get to use it on Windows machine. In this post, I will try my best to explain the whole process step-by-step without any buzz word and confusion. By the way, I tried these steps on Windows 10, not sure if it is applicable in other versions.
Step 1: install python. It seems weird but it is true. The reason is that the minted package uses special library/definition of colors in Pygments package through python. I installed Python 2.7, but I am not sure if the same process would work for Python 3X.
Step 2: Go to the folder in which you installed Python, usually, it is C:Python27. Then, create a new folder and call it “Scripts”. From now on, I will refer to “C:Python27” and “C:Python27Scripts” in the rest of the guidelines. If you install a different version in a different place on your machine, change it accordingly.
Step 3: Push Windows key (between left Ctrl and Alt buttons) and type “System”. Then a window pops up where you should click on “Advanced system settings”, which takes you to a new window. There, click on “Advanced” tab, and select “Environment Variables…” at the bottom. In the new window, you will see two sections: in the “System variables” section, find “Path”, click on it and then select “Edit…” in the bottom of the section. In the new window, you should create new paths to Python and PythonScripts. Select “New” and type “C:Python27”. Do the same for “C:Python27Scripts”. Then, click “Ok” three times.
To check if the two paths are recognised, open a command window (push Windows key and type “cmd”, then better to right click on it and select “run as administrator”) and run SET . You should see the two new paths in the results. If not, you probably need to restart your computer and check again.
Step 4: To check if you installed python appropriately, open a command window (or use the same you already have opened) and run python —version . You should see Python 2.7 (as I installed this version). If you see an error instead of the version of Python on your machine, consult with this page.
Step 5: Let’s see if you have an appropriate version of pip on your machine. Run pip —version in the command window. It should return the version of the pip installed on your machine. If you get an error, you have to install pip by downloading get-pip.py from here, or any other websites. Save the file somewhere outside of Windows environment path. Go to that folder in the command window (using cd command, for instance c:UsersuqapourmDownloads ) and run python get-pip.py . That should install pip on your machine. The good thing is that it will automatically install setuptools for Python.
If you already have pip on your machine, and not setuptools , you should download it in a zip file from here (at this moment, it is named “setuptools-38.5.1.zip”). Unzip the package in a folder outside of Windows environment paths and Python installation path. Then, go to that folder in the command window (remember you should have started command window as an administrator when installing things in there) and run python easy_install.py .
To check the appropriate installation of all the packages so far, run python -m pip install —upgrade pip setuptools wheel in the command line. You should see either up-to-date message for the packages or updating the packages on the command line.
Step 6: Now, we have to install Pygments , as we went this far just to be able to install this package. To do so, run pip install Pygments on the command line. It should be installed easily, you can check successful installation by running pygmentize —version where you should see the version of the package successfully in the command window. Alternatively, you can check Python installation folder (in my case, it is C:Python27Scripts ) where you should see pygmentize.exe .
Step 7: This step is to allow minted package an access to pygmentize.exe from your preferred editor. To do so, go to Windows root (press Windows key and type %SystemRoot%» or directly go to “C:Windows”). Create a text file and rename it to “pygmentize.cmd”. Open the file with a text editor (such as Notepad) and write the following code in there and save it:
@echo off
set PYTHONPATH=C:Python27
%PYTHONPATH%python.exe %PYTHONPATH%Scriptspygmentize.exe %*
We are done! Everything is configured appropriately. There is only one more thing to do. Since minted package requires access to the shell, this should be permitted within your editor. To do so, you have to add -shell-escape to your command list for LaTex, PdfLaTex, XeLaTex, and LuaLaTex in your favourite tex editor. I use “TexStudio” where I can modify those commands by going into “Options > Configure TexStudio > Commands” where I changed the following commands by adding -shell-escape :
latex.exe -shell-escape -src -interaction=nonstopmode %.tex
pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
xelatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
lualatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
Now, it should be all good. You can try this minimal example as a test to make sure everything is working as it should.
You can also save the code in a tex file (let’s say you named it “testMinted.tex”), and compile it from command line by going in to the folder where the file resides (let’s say it is in “C:UsersuqapourmDesktoptestMinted”) and running pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode testMinted.tex in the command line.
P.S. 1: Sometimes, you need to clear the cache in order to get the package to work. This will slow down the operation, but it will avoid errors. To do so, change permeability to usepackage[cache=false] .
Источник
Minted не может найти пигментирование в TexStudio на Windows 7
Я хочу использовать пакет minted , но когда я xelatexing в TexStudio , возникает ошибка:
pip кажется, не может найти пигментирование:
В моем C:Python26Scripts есть файлы с именем pygmentize :
Однако это не работает. Как мне это исправить?
2 ответа 2
Вам нужно только установить Pygments в Python, Pygmentize — это команда, доступная после установки Pygments .
Вы можете проверить, правильно ли он установлен в Windows, и к нему можно получить доступ в PATH, введя в командной строке:
Который распечатает справочное сообщение.
Не забудьте использовать опцию -shell-escape , чтобы ваш tex-компилятор мог получить доступ к внешним командам.
Посмотрите, как это сделать здесь
Убедитесь, что у вас есть все ваши пакеты MiKTeX в актуальном состоянии. В моем случае мое антивирусное программное обеспечение препятствовало обновлению некоторых пакетов MiKTeX, что, в свою очередь, приводило к невозможности их использования.
Я нашел это решение здесь
У меня была точно такая же проблема, но на Windows 10. Сейчас я напишу правильный ответ для будущих пользователей.
Чтобы использовать пакет minted в TeX, необходимо сделать 3 вещи:
Измените вывод pdflatex на -shell-escape,
Убедитесь, что pygmentize установлен в вашей оболочке python, и это наиболее трудно
Убедитесь, что TeX отдает приоритет правильному PATH.
- Перейдите в «Параметры» в предпочитаемом вами редакторе TeX и измените PdfLaTeX на: чем бы он ни был, а затем «-shell-escape% .tex»
- Перейдите в свою оболочку Python, fx Anaconda. Запросите, если вы используете Anaconda в качестве редактора Python. Проверьте, установлен ли pygmentize, написав: «pygmentize -v». Если появится текущая версия, перейдите к решению 3. Если нет, введите: «pip install Pygment». Это должно установить pygmentize в любую папку, которую ваш редактор Python использует для сценариев, что необходимо для следующего решения.
Во-первых, используйте поиск Windows, чтобы найти «pygmentize.exe». Скопируйте путь из адресной строки, fx «C:UsersYourUsernameHereAnaconda3Scripts».
Теперь используйте поиск Windows, чтобы найти «Расширенные настройки системы». Нажав на результат, вы попадете именно на вкладку «Дополнительно» в Системных настройках, если нет, перейдите туда. Там будет кнопка «Переменные среды . », нажмите на нее.
В разделе «Пользовательские переменные для YourUsernameHere» щелкните переменную «Path», а затем нажмите «Edit . ». Создайте новый путь для скопированного пути из предыдущего, fx «C:UsersYourUsernameHereAnaconda3Scripts», а затем нажимайте «Переместить вверх», пока он не окажется выше любых связанных с TeX путей.
Перезагрузите компьютер. Чеканка теперь должна работать 🙂
Надеюсь, это поможет кому-то в будущем сэкономить драгоценное время, которое я потратил впустую. Чистая прибыль!
Источник
When compiling a LaTeX file with the package minted, LaTeXTools fails and says Package minted Error: You must have 'pygmentize' installed to use this package. []
. I have installed it, and everything works fine if I try compiling from the command line (with pdflatex --shell-escape FILENAME.tex
). I’m guessing LaTeXTools is looking for the package in the wrong place, but I am not sure how to fix that, does anyone have any suggestions?
As of right now, Pygments version 2.1.1
is installed at /Library/Frameworks/Python.framework/Versions/3.4/bin/pygmentize
. I am on Mac OSX Yosemite using Sublime Text 3. I can provide further information about my setup as needed if that would help.
(To be clear, I have specified --shell-escape
in the configuration file for LaTeXTools, so that is not the issue as far as I know)
The traditional builder uses latexmk. I would recommend to open the Sublime Text console with View>Show Console
. This prints the executed command, which should be:
['latexmk', '-cd', '-e', '-f', '-pdf', '-interaction=nonstopmode', '-synctex=1', '-latexoption="--shell-escape"', 'your_file.tex']
Hence you could try run to this command in your shell:
'latexmk -cd -e -f -pdf -interaction=nonstopmode -synctex=1 -latexoption="--shell-escape" your_file.tex'
Remember that the shell-escape
option is not platform specific, hence not inside osx
.
This more or less falls under the warnings about the $PATH
on OS X. You need to ensure that your texpath
setting includes not just pdflatex
and friends but any other executables that they might need to launch. So you not only need to set --shell-escape
you need to ensure that pygmantize
is available on the $PATH
, which in your case looks like you need /Library/Frameworks/Python.framework/Versions/3.4/bin
included.
As an alternative, you can redefine the MintedPygmentize
command in your document to the full path to the pygmantize executable, e.g.,
renewcommand{MintedPygmentize}{/Library/Frameworks/Python.framework/Versions/3.4/bin/pygmantize}
@r-stein hmm, I had no idea about latexmk
versus pdflatex
, so I tried using the command you provided (it matched with what my ST console showed me) and the compilation succeeded even though it didn’t work from ST.
@ig0774 you were spot on about adding /Library/Frameworks/Python.framework/Versions/3.4/bin
to my texpath. In my LaTeXTools configuration file, I changed
"texpath" : "$PATH:/usr/texbin:/usr/local/bin:/opt/local/bin"
to
"texpath" : "$PATH:/usr/texbin:/usr/local/bin:/opt/local/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin"
and everything started working like a charm, thank you so much.
Also, just for the record, I tried the other solution first, but it did not work for me and gave me the following errors:
LaTeX Error: MintedPygmentize undefined. [renewcommand{MintedPygmentize}]
LaTeX Error: Command MintedPygmentize already defined. [newcommand{MintedPygmentize}{pygmentize}]
but since changing my texpath
fixed the problem, we’re all good. Thank you all so much!
Hi there, thank for these great answers!
I had the same issues but still struggled a bit. That’s why I wish to share a more detailed answer.
Like @2016rshah I wanted to use the minted package to highlight some Python code in a LaTeX file.
If you only add the usepackage{minted}
in the preamble and then build the .tex
file then you would a priori get 2 errors:
Package minted Error: You must invoke LaTeX with the -shell-escape flag.
Package minted Error: You must have 'pygmentize' installed to use this package.
First, you need to have the Python package Pygments installed
Then you can update the LaTeXTools.sublime-settings
file accordingly
-
Sublime Text -> Preferences -> Package Settings -> LaTexTools -> Settings - User
-
To solve 1. add the
--shell-escape
option in the"builder_settings"
field"builder_settings" : { // General settings: // See README or third-party documentation // SHELL ESCAPE OTPTION "options" : "--shell-escape", // (built-ins): true shows the log of each command in the output panel "display_log" : false, // Platform-specific settings: "osx" : { // See README or third-party documentation }, ... }
-
To solve 2.
- locate the folder where
pygmentize
is saved
$ which pygmentize /Users/ggautier/anaconda/bin/pygmentize
- add the path i.e.
/Users/ggautier/anaconda/bin
in the"texpath"
field
// ------------------------------------------------------------------ // Platform settings: adapt as needed for your machine // ------------------------------------------------------------------ "osx": { // Path used when invoking tex & friends; MUST include $PATH "texpath" : "$PATH:/Users/ggautier/anaconda/bin:/Library/TeX/texbin:/usr/texbin:/usr/local/bin:/opt/local/bin:" // Path to PDF viewer, if needed // TODO think about it. Also, maybe configure it here! }
- locate the folder where
Hopefully, you should be fine!
wumengyangok, ZhangYifeng1995, and izackwu reacted with laugh emoji
wumengyangok, ZhangYifeng1995, greyxray, izackwu, and typemoe reacted with hooray emoji
wumengyangok, ZhangYifeng1995, greyxray, pacosalces, izackwu, and steve0el0crack reacted with heart emoji
Minted is used add beauty to code in LaTex, like in:
documentclass{article}
usepackage{minted}
begin{document}
begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
end{minted}
end{document}
I’ve installed it and it works fine if I call, from the command line:
pdflatex -shell-escape minimal.tex
But I’m using Sublime Text Build System to make the PDF, here is the build script:
{
"cmd": ["/Library/TeX/texbin/pdflatex","-shell-escape","$file"],
"selector": "text.tex.latex"
}
For some reason when I hit Ctrl+B
, it doesn’t work as in the Terminal. In the output panel I see:
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
write18 enabled.
entering extended mode
(/Users/user/Downloads/minted/minimal.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2016/texmf-dist/tex/latex/minted/minted.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix
<2008/02/07> (tvz))
(/usr/local/texlive/2016/texmf-dist/tex/latex/float/float.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/ifplatform/ifplatform.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/catchfile.sty)
(./minimal.w18))
(/usr/local/texlive/2016/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/local/texlive/2016/texmf-dist/tex/latex/lineno/lineno.sty))
(./_minted-minimal/default.pygstyle)system returned with code 256
! Package minted Error: You must have `pygmentize' installed to use this packag
e.
See the minted package documentation for explanation.
Type H <return> for immediate help.
...
l.3 begin{document}
?
Why pygmentize
isn’t found via Sublime Text?
I was looking for a package to format programming code inside document for a specific programming language. There are two popular options, which are
minted
and listings
. Between the two options, I found minted
more flexible and easy to use, of course only when installed. It allows you to easily specify the programming language of your interest, to format margins, line spacing, footnoting, reading from an actual code file, and other things. I am a Windows user (unfortunately) and installing minted is not as easy as you might think. I found no comprehensive guidelines to install this package and get to use it on Windows machine. In this post, I will try my best to explain the whole process step-by-step without any buzz word and confusion. By the way, I tried these steps on Windows 10, not sure if it is applicable in other versions.
Step 1: install python. It seems weird but it is true. The reason is that the minted
package uses special library/definition of colors in Pygments
package through python. I installed Python 2.7, but I am not sure if the same process would work for Python 3X.
Step 2: Go to the folder in which you installed Python, usually, it is C:Python27. Then, create a new folder and call it “Scripts”. From now on, I will refer to “C:Python27” and “C:Python27Scripts” in the rest of the guidelines. If you install a different version in a different place on your machine, change it accordingly.
Step 3: Push Windows key (between left Ctrl and Alt buttons) and type “System”. Then a window pops up where you should click on “Advanced system settings”, which takes you to a new window. There, click on “Advanced” tab, and select “Environment Variables…” at the bottom. In the new window, you will see two sections: in the “System variables” section, find “Path”, click on it and then select “Edit…” in the bottom of the section. In the new window, you should create new paths to Python and PythonScripts. Select “New” and type “C:Python27”. Do the same for “C:Python27Scripts”. Then, click “Ok” three times.
To check if the two paths are recognised, open a command window (push Windows key and type “cmd”, then better to right click on it and select “run as administrator”) and run SET
. You should see the two new paths in the results. If not, you probably need to restart your computer and check again.
Step 4: To check if you installed python appropriately, open a command window (or use the same you already have opened) and run python --version
. You should see Python 2.7 (as I installed this version). If you see an error instead of the version of Python on your machine, consult with this page.
Step 5: Let’s see if you have an appropriate version of pip
on your machine. Run pip --version
in the command window. It should return the version of the pip installed on your machine. If you get an error, you have to install pip by downloading get-pip.py
from here, or any other websites. Save the file somewhere outside of Windows environment path. Go to that folder in the command window (using cd
command, for instance c:UsersuqapourmDownloads
) and run python get-pip.py
. That should install pip
on your machine. The good thing is that it will automatically install setuptools
for Python.
If you already have pip
on your machine, and not setuptools
, you should download it in a zip file from here (at this moment, it is named “setuptools-38.5.1.zip”). Unzip the package in a folder outside of Windows environment paths and Python installation path. Then, go to that folder in the command window (remember you should have started command window as an administrator when installing things in there) and run python easy_install.py
.
To check the appropriate installation of all the packages so far, run python -m pip install --upgrade pip setuptools wheel
in the command line. You should see either up-to-date message for the packages or updating the packages on the command line.
Step 6: Now, we have to install Pygments
, as we went this far just to be able to install this package. To do so, run pip install Pygments
on the command line. It should be installed easily, you can check successful installation by running pygmentize --version
where you should see the version of the package successfully in the command window. Alternatively, you can check Python installation folder (in my case, it is C:Python27Scripts
) where you should see pygmentize.exe
.
Step 7: This step is to allow minted
package an access to pygmentize.exe
from your preferred editor. To do so, go to Windows root (press Windows key and type
%SystemRoot%"
or directly go to “C:Windows”). Create a text file and rename it to “pygmentize.cmd”. Open the file with a text editor (such as Notepad) and write the following code in there and save it:
@echo off
set PYTHONPATH=C:Python27
%PYTHONPATH%python.exe %PYTHONPATH%Scriptspygmentize.exe %*
We are done! Everything is configured appropriately. There is only one more thing to do. Since minted
package requires access to the shell, this should be permitted within your editor. To do so, you have to add
-shell-escape
to your command list for LaTex, PdfLaTex, XeLaTex, and LuaLaTex in your favourite tex editor. I use “TexStudio” where I can modify those commands by going into “Options > Configure TexStudio > Commands” where I changed the following commands by adding -shell-escape
:
latex.exe -shell-escape -src -interaction=nonstopmode %.tex
pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
xelatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
lualatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
Now, it should be all good. You can try this minimal example as a test to make sure everything is working as it should.
documentclass[10pt,a4paper]{article} usepackage[english]{babel} usepackage[utf8x]{inputenc} usepackage{minted} begin{document} begin{minted}{python} import numpy as np def incmatrix(genl1,genl2): m = len(genl1) n = len(genl2) M = None #to become the incidence matrix VT = np.zeros((n*m,1), int) #dummy variable #compute the bitwise xor matrix M1 = bitxormatrix(genl1) M2 = np.triu(bitxormatrix(genl2),1) for i in range(m-1): for j in range(i+1, m): [r,c] = np.where(M2 == M1[i,j]) for k in range(len(r)): VT[(i)*n + r[k]] = 1; VT[(i)*n + c[k]] = 1; VT[(j)*n + r[k]] = 1; VT[(j)*n + c[k]] = 1; if M is None: M = np.copy(VT) else: M = np.concatenate((M, VT), 1) VT = np.zeros((n*m,1), int) return M end{minted} end{document}
You can also save the code in a tex file (let’s say you named it “testMinted.tex”), and compile it from command line by going in to the folder where the file resides (let’s say it is in “C:UsersuqapourmDesktoptestMinted”) and running pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode testMinted.tex
in the command line.
P.S. 1: Sometimes, you need to clear the cache in order to get the package to work. This will slow down the operation, but it will avoid errors. To do so, change permeability to
usepackage[cache=false]{minted}
.
P.S. 2: If you are using “TexStudio”, then new packages should be installed automatically. If not, you can install minted
package directly, by pressing Windows key, type “MiKTeX Package Manager” and then find “minted” from the list, right-click on it and push install button. If your preferred repository is down for some reason, then you should go to “repository” tab, select “Change Package Repository”, push “Next” and select another online repository from the list.
I want to use minted package, but when I’m xelatexing
in TexStudio
, there’s an error:
minted: You must have `pygmentize' installed to use this package.
pip
seems unable to find pygmentize:
In my C:Python26Scripts
there are files named pygmentize
:
I have followed instructions from here https://tex.stackexchange.com/questions/108661/how-to-use-minted-under-miktex-and-windows-7 where it is suggested to install Pygments which is what I did:
This is my PATH:
C:UsersMilosAppDataRoamingnpm;C:Python26;C:Python26Scripts
However it is not working. How should I fix this?
asked Sep 24, 2014 at 20:46
9
I had the exact same problem, but on Windows 10. I will now write a proper answer for future users.
There are 3 things that must be done in order to use the minted package in TeX:
-
Change your pdflatex output to include -shell-escape,
-
Make sure pygmentize is installed in your python shell, and most difficultly
-
Make sure TeX prioritizes the correct PATH.
Solutions:
- Go to Options in your preferred TeX editor and change the PdfLaTeX
to: whatever it was before and then «-shell-escape %.tex» - Go to your Python Shell, fx Anaconda Prompt if you’re using Anaconda
as your Python editor. Check if pygmentize is already installed by
writing:pygmentize -V
. If it brings up your current version,
continue to solution 3. If not, type:pip install Pygments
. This
should install pygmentize in whatever folder your Python editor uses
for scripts, which is needed for the next solution. -
First, use Windows search to find «pygmentize.exe». Copy the path
from the address bar, fx
«C:UsersYourUsernameHereAnaconda3Scripts».Now use Windows search to find «Advanced System Settings». Clicking
on the result should bring you exactly to the «Advanced» tab of the
System Settings, if not, go there. There will be a button for
«Environment Variables…», click on it.Under the «User variables for YourUsernameHere», click on the
variable «Path» and then click «Edit…». Create a new path for the
copied path from earlier, fx
«C:UsersYourUsernameHereAnaconda3Scripts», and then click «Move
up» until it is above any TeX related paths.Restart your computer. Minted should now work
Hope this helps someone in the future save precious time that I wasted myself. Net gain!
answered Dec 12, 2018 at 4:43
HectorHector
911 silver badge3 bronze badges
1
-
You need only to install
Pygments
into Python,Pygmentize
is a command available oncePygments
have been installed.You can check it has been properly installed on Windows and can be accessed in the PATH by typing in a command line:
pygmentize -h
Which will print the help message.
-
Don’t forget to use the
-shell-escape
option in order to allow your tex compiler to access the external commands.See how to do it here
-
Make sure you have all your MiKTeX packages up to date.
In my case, my antivirus software was preventing some MiKTeX packages updates, which in turn where making minted unusable.I fount this solution here
- As @darthbith suggested in the comments, closing and reopening (or a system restart) can be needed for the PATH to be reloaded.
answered Aug 13, 2016 at 12:09
ToghTogh
4713 silver badges5 bronze badges
#1 2011-06-22 14:47:20
- cap_sensitive
- Member
- Registered: 2010-04-05
- Posts: 35
[SOLVED]LaTeX minted and pygmentize issue
I encountered a issue when «compiling» a LaTeX file by xelatex:
The File:
documentclass[12pt,a4paper]{article}
usepackage{hyperref}
usepackage{minted}
begin{document}
begin{minted}[ruby]
=begin
Usual operators:
+ addition
- subtraction
* multiplication
/ division
=end
a = 5 + 3
b = 5 / 3
end{document}
The error message:
! Package minted Error: You must have `pygmentize' installed to use this packag
e.
But I (seem) installed all required packages:
texlive-core 2010.22154-1; texlive-latexextra 2010.22155-1; python-pygments 1.4-3; python2-pygments 1.4-3
[edit]I know this is OT here, but I don’t know where it should be posted. So…
Last edited by cap_sensitive (2011-06-23 04:06:16)
#2 2011-06-22 15:34:21
- Mystal
- Member
- From: fancy glass enclosure
- Registered: 2007-04-27
- Posts: 13
Re: [SOLVED]LaTeX minted and pygmentize issue
You’re close, but there are a few things missing in your file and your command:
begin{minted}{ruby} <== The programming language is a required argument, so curly braces
=begin
Usual operators:
+ addition
- subtraction
* multiplication
/ division
=end
a = 5 + 3
b = 5 / 3
end{minted} <== You need to end the minted block
Finally, minted requires that you compile with the —shell-escape flag:
xelatex --shell-escape <file>
This worked for me, hopefully it’ll fix your issues.
Oh, and I would think this thread would probably be fine in the General Programming Forum.
#3 2011-06-22 23:10:45
- ngoonee
- Forum Fellow
- From: Between Thailand and Singapore
- Registered: 2009-03-17
- Posts: 7,342
Re: [SOLVED]LaTeX minted and pygmentize issue
Moving to General Programming. And yes, shell-escape is what you need (came across the same thing when I started using minted a month or so back).
Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.
#4 2011-06-23 01:03:34
- cap_sensitive
- Member
- Registered: 2010-04-05
- Posts: 35
Re: [SOLVED]LaTeX minted and pygmentize issue
Problem solved. Thanks a lot!
Go to the «Preferences» menu in Texmaker and choose the «Commands» tab. In line next to «PdfLaTeX» there should be
"/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode %.tex
change it to —
"/usr/texbin/pdflatex" -synctex=1 -shell-escape -interaction=nonstopmode %.tex
Got the solution from here
Related videos on Youtube
09 : 47
How to Fix PyCharm Import Error and Setup Your Interpreter
04 : 48
Access denied for user ‘root’@’localhost'(using password: NO)|wampserver 2 out of 3 services running
05 : 26
code: ‘MODULE_NOT_FOUND’ | Bug Report | NODE JS | Beginners
10 : 37
HOW TO FIX THIS ERROR — «venvScriptspython.exe: can’t find ‘__main__’ module» | 2021 | Simple way
02 : 35
How to FIX VSCode error in PyQt5 import pylint(no-name-in-module) & pylint(missing-class-docstring)
Comments
-
I am trying to use
minted
package, which has a dependency of the program calledpygmentize
. I installed this but did not working well. Then i did this But still showing the error:File `pymentize.sty' not found.
when i write this:
usepackage{pymentize} usepackage{minted}
I am using mac sierra and texstudio. Help me please.
-
pygmentize
is not a LaTeX package. It is a Python package. So you should remove thepygmentize
package import (you may have to installpygments
which includespygmentize
using the Python package manager to letminted
work afterwards). -
yes, i installed pygments by ‘sudo easy_install Pygments’ command and which is in ‘usrlocalbin’ folder. Then still I get the error ‘Package minted Error: You must have `pygmentize’ installed to use this package.’
-
No, How can find it, what should i put pygmentize there?
-
@sovon Can you start pygmentize from the command line?
-
yes, i can. I run ‘pygmentize test.py’ command and it works
-