31

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,

1
  • 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 5, 2016 at 11:30

6 Answers 6

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.

13
  • @Konrad Rudolph: Without the fix for \TestAppExists I get TeX asking for \@apppathifexists=, which does not much good!
    – Joseph Wright
    Jul 19, 2011 at 8: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, 2011 at 8: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, 2011 at 2: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, 2011 at 4:02
  • 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 6, 2012 at 9:11
24

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.

1
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.

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.

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.

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .