32

I followed the instruction from this link: http://tug.ctan.org/tex-archive/macros/latex/contrib/minted/

enter image description here

Firstly, I install Python 2.7, then create a folder named Scripts in the directory:

C:\Python27

So I got C:\Python27\Scripts Then I create a file named pygmentize.cmd with the content:

@echo off
set PYTHONPATH=C:\Python27
%PYTHONPATH%\python.exe %PYTHONPATH%Scripts\pygmentize %*

At this point, I already set the path environment variable to C:\Python27 and C:\Python27\Scripts.
Next I installed setuptools-0.6c11.win32-py2.7.exe (md5) from http://pypi.python.org/pypi/setuptools And install Pygments with the following command

easy_install Pygments

Next I include the line \usepackage{minted} to let TexMaker do the installation.

Inside TexMaker, I also change the PdfLaTex option to: pdflatex -shell-escape -interaction=nonstopmode %.tex

Then I tried out a simple example:

\documentclass[12pt,letterpaper]{article}
\usepackage[latin1]{inputenc}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{minted}

\begin{document}
    \begin{minted}{python}
    def boring(args = None):
    pass
    \end{minted}
\end{document}

And the compiler generated these error:

!Emergency stop.<read 2> \TestAppExists{pygmentize}
!==> Fatal error occured, no output PDF file produced!

I guessed the pygmentize was not installed properly so TexMaker wasn't able to run it. I read the instruction over, and couldn't figure out what could cause these errors? Has anyone done it before could share me some lights?

Thank you,

roxrook
  • 9,907
  • Python 3.4 and newer as well as Python 2.7.9 and newer come with pip included, which makes installing Pygments a lot easier! This question is now more or less obsolete. – matth Sep 05 '16 at 11:30

6 Answers6

25

Python 3.4 and newer come with the package manager pip already included:
http://docs.python.org/3.4/whatsnew/3.4.html

Setting up minted+Pygments has therefore become very easy:

  1. Install the latest Python 3.x (PATH can be set during installation).
  2. From a normal command prompt, run python -m pip install -U pygments. This will create a pygmentize.exe in the Pythons Scripts directory.
  3. You are done. Using \usepackage{minted} in .tex files should now work.

Of course, pdfLaTeX (or whatever engine/format you use) still has to be called with the -shell-escape option.

matth
  • 12,381
18

On my Windows 7 system, the following got things working:

That is it install-wise: the current Pygmentize does come with a Windows executable. You can test this by doing pygmentize -V at the Command Prompt.

What I then found is that the test that minted uses for Pygmentize on Windows is broken. So I used the lines

\newcommand\TestAppExists[3]{#2}
\usepackage{minted}

to bypass the test (this basically forces the TRUE branch). The example document then compiles fine.

schlamar
  • 738
  • 6
  • 15
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • @Konrad Rudolph: Without the fix for \TestAppExists I get TeX asking for \@apppathifexists=, which does not much good! – Joseph Wright Jul 19 '11 at 08:04
  • @Chan: Just to point out that I'm using TeX Live 2010. I don't think this should make too much difference to the result, although there are occasional differences in file handling between TeX Live and MiKTeX. – Joseph Wright Jul 19 '11 at 08:06
  • Thank you for your solution. I think I got all the steps set up correctly, except the fix for \newcommand. I wonder where should I add these two lines? inside my .tex or inside the minted.sty. I added in my .tex and I got another error. – roxrook Jul 20 '11 at 02:42
  • I tried out your solution on Ubuntu and it worked perfectly. I still couldn't figure out why it was broken on Windows :(. – roxrook Jul 20 '11 at 04:02
  • @Chan: On my system, I added the \newcommand part in the main .tex file, just before loading minted. That was because my initial trial failed to work, with TeX waiting for some kind of keyboard input. The Pygmentize installation itself went fine, as checked at the Command Prompt using pymgmetize -V. – Joseph Wright Jul 21 '11 at 06:53
  • I ran pygmentize -V, and the output was: Pygments version 1.4, (c) 2006-2008 by Georg Brandl. So I guess it was installed correctly. By the way, do you have your pygmentize.cmd in the Scripts folder? And what do you have in your minted folder? I only have minted.sty, does it sounds reasonable? – roxrook Jul 21 '11 at 16:57
  • @Chan: No, I have pygmentize.exe and pygmentize-script.py. Just minted.sty is entirely correct for the minted side of things. – Joseph Wright Jul 21 '11 at 16:58
  • That's exactly what I got. Don't know why keep getting these errors: ! Package minted Error: You must havepygmentize' installed to use this package` – roxrook Jul 21 '11 at 17:10
  • The test minted uses was only tested on Windows XP, where it works fine. Windows 7 apparently changes its parsing of batch commands. Unfortunately, I have to maintain the “not supported” status since I haven’t got Windows. – Konrad Rudolph Jul 25 '11 at 09:03
  • When I do "easy_install Pygmentize" then I get "Couldn't find index page for 'Pygmentize' (maybe misspelled?)". Does anyone know what's going wrong there? – Benny Code May 05 '12 at 15:29
  • 4
    Found the problem. Under my Windows it was "easy_install Pygments" and then I had to do "pygmentize.exe -V" to see the output. – Benny Code May 06 '12 at 09:11
  • If you install pygments with pip (see my answer below) everything works fine and there is no need for a workaround. – schlamar May 10 '12 at 10:14
  • Maybe this answer could be update to no longer recommend Python 2? https://python3statement.org/ – matth May 16 '19 at 08:11
13

The problem might be due to issues with setuptools (for example with UAC).

Here is an installation procedure which is working for me:

  1. Install Python 2.7

  2. Install distribute (replacement for setuptools because it is buggy and no more maintained)

  3. Add C:\Python27\Scripts to your PATH

  4. Install pip: easy_install pip

  5. Install pygments: pip install pygments

These steps create a pygmentize.exe, so there is no need to create the batch file.

schlamar
  • 738
  • 6
  • 15
4

Re-installing minted fixed the issue. To uninstall a package in MikTex, go to Package Manager (Admin). Reinstall minted under TexMaker, after that I don't even need the \newcommand\TestAppExists[3]{#2}. Just make sure you add the scripts pygmentize.cmd to the C:\Python27\Scripts\ with the content:

@echo off
set PYTHONPATH=C:\Python27
%PYTHONPATH%\python.exe %PYTHONPATH%\Scripts\pygmentize %*

Note: The one in the instruction document missed a \ after %PYTHON%. Further, this solution only works under Windows environment, for Linux variants, you have to go with Joseph Wright's solution.

roxrook
  • 9,907
3

I have Windows 10 and I think Joseph's answer should be updated.

In the following there is what I've just done to install Pigmentize, I don't know if there are some unnecessary steps but, in my case, this worked.

Dowload Python

I've downloaded and installed the latest release of Python for Windows.

Install setuptools

Since distribute is deprecated now, I've used setuptools, in the command prompt, I've run (see here):

python -m pip install -U pip setuptools

Add Python paths to system paths

In my system path I've added:

C:\Users\myuser\AppData\Local\Programs\Python\Python36\Scripts

and also:

C:\Users\myuser\AppData\Local\Programs\Python\Python36

Install pygments

In the command prompt, I've run:

easy_install pygments

Restart Windows

After restarting Windows all works.

CarLaTeX
  • 62,716
2

So this is a bit late, but I got everything to work on Windows 7 and I can compile and create my pdf within TeXworks using MiKTeX. (I apologize for improper formatting. Doing this late at night and have not done this before, but I wanted to type it somewhere before I forget)

  1. Install Python 2.7
  2. Install setuptools-0.6c11.win32-py2.7.exe
  3. Add C:\Python27\Scripts to your PATH (just google how to do this if you don't know how)
  4. Navigate to your Scripts folder and run "easy_install Pygments" in the command prompt
  5. Make a file called "pygmentize.cmd" in the Scripts folder with the contents: @echo off set PYTHONPATH=C:\Python27 %PYTHONPATH%\python.exe %PYTHONPATH%\Scripts\pygmentize %*

As of now, if you run "pdflatex --shell-escape myFileName.tex" in the command prompt it will work. If you want it to work within TeXworks (and I assume other similar programs), you have to make one extra step.

  1. Click edit-->preferences, then go to the Typesetting tab. Click the "+" and add your Scripts directory ("C:\Python27\Scripts")

Now it works! Yay! With this set of steps, the \newcommand\TestAppExists[3]{#2} is not needed.

bgodbgg
  • 21