16

I use a Mac OS X 10.8, and want to run the latexindent.pl perl script on my latex files. This script is made by https://github.com/cmhughes/latexindent.plx. When I run this script on a latexfile I get this error message:

Can't locate File/HomeDir.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4/darwin-thread-multi-2level /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at helloworld.pl line 10.
BEGIN failed--compilation aborted at helloworld.pl line 10.

It seems that I am missing the File::HomeDir module in perl so I tried to download it using:

sudo perl -MCPAN -e 'install File::HomeDir',

I get the following error:

Can't locate object method "install" via package "File::HomeDir".

I managed to install the YAML::Tiny package without any problems.

I tried to run:

1 #!/usr/bin/perl
2 
3 use strict;
4 use warnings;
5 use FindBin;
6 use YAML::Tiny;
7 use File::Copy;
8 use File::Basename;
9 use Getopt::Std;
10 use File::HomeDir;
11 
12 print "hello world";
13 exit;         

and got the same Error message as above...

Do anyone know what to do?

bgs
  • 3,061
  • 7
  • 40
  • 58
Yang Min Wang
  • 161
  • 1
  • 1
  • 3

3 Answers3

21
sudo perl -MCPAN -e 'install "File::HomeDir"'
                             ^             ^
ikegami
  • 367,544
  • 15
  • 269
  • 518
8

I had a similar problem. I just ran these commends, and it worked for me

sudo cpan -i File::HomeDir

then

sudo cpan -i Unicode::GCString

Basically, I will run latexindent file_name.tex, then an error message will appear that says you may need to install the XXXX module then I install the XXXX module using sudo cpan -i XXXX

Faisal
  • 81
  • 1
  • 2
1

I just had this problem with macOS M1. If you don't want to use sudo, which I would strongly recommend not to. You can install the formulae latexindent via brew:

brew install latexindent

This fixed my issue without having to use sudo.

David Vale
  • 136
  • 1
  • 7