I have Strawberry Perl and MiKTeX v2.9 installed on Windows 10 with the latexindent package installed via the MiKTeX console.

However, running latexindent.pl in the command prompt results in the following error

Can't locate Log/Log4perl.pm in @INC (you may need to install the Log::Log4perl module) (@INC contains: C:/Program Files/MiKTeX 2.9/scripts/latexindent C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22. BEGIN failed--compilation aborted at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22. Compilation failed in require at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/Document.pm line 25. BEGIN failed--compilation aborted at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/Document.pm line 25. Compilation failed in require at C:\Program Files\MiKTeX 2.9\scripts\latexindent\latexindent.pl line 27. BEGIN failed--compilation aborted at C:\Program Files\MiKTeX 2.9\scripts\latexindent\latexindent.pl line 27.

Additionally, this answer doesn't help in removing the error. So, what is missing here?

  • 5
    Your Perl distribution is missing a module that's required by latexindent. The simplest way of installing a Perl module is using cpan. See What's the easiest way to install a missing Perl module? and Installing modules using Strawberry Perl on StackOverflow. – Nicola Talbot Aug 10 '18 at 16:01
  • 1
    for Windows users, there is also latexindent.exe which doesn't need a perl installation. available from ctan ctan.org/pkg/latexindent – cmhughes Aug 17 '18 at 16:53
  • 1
    to anyone reading this: I'd really like help in trying to communicate how to install perl modules and/or latexindent. the vast majority of questions on this site revolve around installation, which means that I clearly need to do more work in helping. please feel free to help me with this at http://github.com/cmhughes/latexindent.pl/ – cmhughes Aug 17 '18 at 17:00

For others running into the same issue but on a Mac:

Install perl via brew:

brew install perl

Use cpan to install the necessary perl packages:

Open cpan and select yes if necessary to setup the config automatically:


Then install any packages mentioned in your error logs, you may need to install and retry several times to figure out all of the packages you need.

In my case these packages fixed the error messages:

install Log::Log4perl
install Log::Dispatch::File
install YAML::Tiny
install File::HomeDir

Catalina Update

If the installation fails with an error message that sounds like a permissions issue, that may be due to security changes in Catalina. In that case, try forcing the installation:

cpan -fi \
  Log::Log4perl \
  Log::Dispatch::File \
  YAML::Tiny \
  File::HomeDir \
  • 1
    The question is for OS W10. – Sebastiano Dec 22 '19 at 19:06
  • 23
    People searching for the same issue on a Mac (per my case) also end up on this page. – songololo Dec 22 '19 at 19:38
  • 6
    I also needed install Unicode::GCString Mac catalina and TeXLive 2019 – Spangen Apr 19 '20 at 9:29
  • I don't understand how to install brew without first installing perl. How do I do that? – LaTeXereXeTaL Jul 18 '20 at 1:40
  • 2
    @LaTeXereXeTaL brew is a separate package manager on the Mac. It is completely unrelated to Latex but allows you to install third-party packages (like perl in this case) that might be used by Latex. Google "homebrew" for installation instructions. – songololo Jul 22 '20 at 10:26

Thanks to @Nicola's comment, the error can be fixed as follows:

  1. The missing module is Log::Log4perl as found in the first line of the error.
  2. Open Win 10 start menu and search for CPAN client, then open it and run install Log::Log4perl. However, it may fail due to the common bug, which needs the installtion to be forced by running force install Log::Log4perl (from the CPAN client) or the other command prompt commands given by the answers to this question. In other words, for instance, the command cpan -f -i Log::Log4perl must be run from the command prompt NOT the CPAN client.
  3. Another module might be missing whose name can be identified as similarly done in the first step and installed the same way.
  • 9
    For the record, on my Debian, the additional missing modules where Log::LogDispatch, Log::Dispatch::File, YAML::Tiny and File::HomeDir. You can install them all at once using cpan Log::LogDispatch Log::Dispatch::File YAML::Tiny File::HomeDir. – Clément Dec 23 '18 at 2:19
  • 3
    For MacOS, this also included Unicode::GCString, so the full installation solution was: cpan -i Log::Log4perl Log::LogDispatch Log::Dispatch::File YAML::Tiny File::HomeDir Unicode::GCString. This should be packaged to run at the end of brew install mactex. – Adam Erickson Sep 5 '19 at 20:27
  • @Clément cpan Log::Dispatch Log::Dispatch::File YAML::Tiny File::HomeDir – Bonjour123 May 3 '20 at 1:30
  • This solution finally got latexindent working after over two hours of trying to get it to work on my Mac. The perl installation didn't correctly update my PATH and I had to manually fix that. Then, as described here, I had to install the modules from inside cpan and none of the other documentation mentions that. Pretty frustrating experience. I hope I can get latexindent working on my MacBook Pro without the hassle. – LaTeXereXeTaL Jul 18 '20 at 1:39
  • 1
    Too much installation just for indenting automatically – Emre Sülün Sep 21 '20 at 13:46

MacOS Big Sur

New problems arise for Big Sur. Here is my Fix.

(The solution assumed you've installed homebrew. )

Step 1. Install the perl & its package manager

brew install perl
brew install cpanm

Step 2. Create symlink for MacOSX10.14.sdk

Install the missing packages directly will raise the build error:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]

That's because:

Apple decided to stop naming their SDKs with versions but rather name them MacOSX.sdk and include an alias with the version name for compatibility

So we create symlink for this folder. (Difference between recent SDKs is minor)

> cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
> sudo ln -s MacOSX.sdk MacOSX10.14.sdk

Step 3. Install the missing packages

cpanm YAML::Tiny
cpanm File::HomeDir
cpanm Unicode::GCString
cpanm Log::Log4perl
cpanm Log::Dispatch
New contributor
Boyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.