Exiftool Perl script error (Can't locate Image/ExifTool.pm in @INC)

Started by msandersen, September 08, 2024, 12:56:37 PM

Previous topic - Next topic

msandersen

I came across a basic Perl error in my Perl Exiftool script on Mac (Sonoma), which works fine normally, but now Image::Exiftool seem to be missing.
I tried reinstalling Exiftool with a freshly-downloaded package from here and restarting, and also checking Homebrew didn't have a version installed. I assume it's some sort of Environment variable issue, which shouldn't have changed. The error makes mention of a particular version of Perl.
Perl --version yields v5.34.1
I don't know enough about Unix or Bash to figure out how to fix it though.

Line 6 in my script is: use Image::ExifTool;Error:
Can't locate Image/ExifTool.pm in @INC (you may need to install the Image::ExifTool module) (@INC contains: /Library/Perl/5.34/darwin-thread-multi-2level /Library/Perl/5.34 /Network/Library/Perl/5.34/darwin-thread-multi-2level /Network/Library/Perl/5.34 /Library/Perl/Updates/5.34.1 /System/Library/Perl/5.34/darwin-thread-multi-2level /System/Library/Perl/5.34 /System/Library/Perl/Extras/5.34/darwin-thread-multi-2level /System/Library/Perl/Extras/5.34) at /Users/thor/Exiftool_Description_FP3FujiTags.pl line 6.

StarGeek

Perl is looking for the exiftool files in these directories
/Library/Perl/5.34/darwin-thread-multi-2level
/Library/Perl/5.34
/Network/Library/Perl/5.34/darwin-thread-multi-2level
/Network/Library/Perl/5.34
/Library/Perl/Updates/5.34.1
/System/Library/Perl/5.34/darwin-thread-multi-2level
/System/Library/Perl/5.34
/System/Library/Perl/Extras/5.34/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.34

If exiftool Image and File directories aren't in these, the Perl can't find them.

Unfortunately, I don't use a Mac so I don't know the best way to resolve this, especially since you're calling Image::Exiftool and not the command line program.

Hopefully, one of the Mac users here might be able to help. Phil is currently away for a week, so it will be a bit before he can get to this.

You might try the Unix install instructions instead. From the Mac install instructions
QuoteThe Unix install has the advantage of making the ExifTool library available for your Perl scripts...
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

msandersen

I should clarify that Exiftool works as expected from the Terminal, and I ran an upgrade on my package manager, called Homebrew, which manages, downloads and installs various Unix tools and their dependencies. It doesn't have any other competing install of Exiftool, but seems to have several versions of Perl, presumably as dependencies for other packages. It also shows the compiler works as it should. My understanding is that the Exiftool Perl API, which is the one it can't find, should be a folder under the same install directory. I don't know enough about this though. I just know it used to work as it should. Maybe it's a permissions issue.

EDIT:
I checked the installed Version with exiftool -ver turns out it's using an older version, 12.65, even though I installed a fresh package and none was installed via Homebrew. A "locate exiftool" found it under Macports, another package manager I've used in the past. It wasn't operational as it was installed under a previous OS version, and not listed in the $PATH variable, but somehow it is being preferenced over the version the official installed puts in /urs/local/bin
So I've reinstalled Macports, upgraded all packages, which brought it's version of Exiftool up to the current one, but the Perl script fails all the same on the missing image-exiftool API. I then uninstalled the Macports version and did a clean of the packages to remove any trace, and tried again. Still fails. I may have to restart to see if that clears something, but will do that tonight when I've finished my other work. Iocate only finds the versions used by various app packages like Geotag Photos, Digikam, or JexiftoolGui; they're all older versions. The version number on the terminal is the correct current one now though.

bodacious

I install Exiftools via MacPorts. I'm not sure if this is the same issue, but a similar problem exists there, too. Here is a discussion about the Port: https://trac.macports.org/ticket/70459

edit: for anyone googling, I seem to have fixed my issue by installing the `perl5` Port. Typically I would not bother, and just install exiftool.

StarGeek

Quote from: msandersen on September 11, 2024, 03:57:53 AMI should clarify that Exiftool works as expected from the Terminal

That's to be expected. When calling the exiftool script, exiftool looks for the rest of the files in the directory where the script is located. In this case, the exiftool script just needs to be one of the PATH directories.

QuoteMy understanding is that the Exiftool Perl API, which is the one it can't find, should be a folder under the same install directory.

The Perl API needs to be someplace where Perl can find it, which is in the directories listed by @INC as shown above. Perl doesn't check the PATH directories when looking for library modules.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

msandersen

Ah I see. I thought it had something to do with the $PATH
Exiftool installs to
/usr/local/bin
and indeed Exiftool.pm is located at
/usr/local/bin/lib/Image/ExifTool.pm
and there also seem to be one at
/opt/local/lib/perl5/vendor_perl/5.34/Image/ExifTool.pm
none of which are in the @Include path mentioned. The /lib folder is in the same directory as the exiftool executable, which is what I expected, but the system somehow doesn't. Perhaps I will place a Symlink into one of those locations unless there is a way to tell it to include the right path.
One thing I noticed is that while the current Perl version is v5.34.1, some of the @INC paths only say 5.34

StarGeek

shows how you could permanently add /usr/local/bin/ (or maybe it should be [tt/usr/local/bin/lib) to @INC.

Or you could copy/paste the contents of [tt/usr/local/bin/lib[/url] into a lib directory in one of the already existing paths, such as /Library/Perl/5.34. A symlink for the /image/ and /File/ might also work.

Phil should be back soon and might have a better solution.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

msandersen

I found this from Perl Maven:
How to change @INC to find Perl modules in non-standard locations
and as a temporary measure that works for this script, added a 'use lib' statement before the 'use image::exiftool' statement before to add it to the @INC path for that script only:
use lib '/usr/local/bin/lib';
use Image::ExifTool;
The script now runs.
For a more permanent solution, I have to add export PERL5LIB=/usr/local/bin/lib to the Shell config. OSX uses ZSH shell, so there seem to be 3 locations I can add it; Macports uses .zprofile, but there is also .zshrc and .zshenv
so something like
echo 'export PERL5LIB=/usr/local/bin/lib' >> ~/.zprofile in the Terminal should work. I already ran the script, but will experiment later.

Phil Harvey

ExifTool does it this way:

BEGIN { push @INC, '/usr/local/bin/lib' }
- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

msandersen

Quote from: Phil Harvey on September 12, 2024, 09:00:16 PMExifTool does it this way:

BEGIN { push @INC, '/usr/local/bin/lib' }
- Phil
Welcome back.
I assume that's in Exiftool itself not the installer. But then either way after I reinstalled with a fresh package from here, shouldn't it have registered it somewhere? It had been working, but something that's changed, something I've installed perhaps, means it's not registered that path according to the error.

Otherwise, is it something to put in one of the config files?
For now, I have export PERL5LIB=/usr/local/bin/lib in ~/.zprofile, the file Macports and Homebrew uses. Not sure if I need to add :$PERL5LIB onto the end, like you do with $PATH
I don't know much about scripting or Perl, so maybe it's something I have to add in the header section.
Currently it starts
#!/usr/bin/perl

use strict;
use warnings;
use File::Find;
use lib '/usr/local/bin/lib';
use Image::ExifTool;
use XML::LibXML;
It finds the other modules without prompting, but had to add the 'use lib' line as a temporary fix.
I won't know until the next time I need to run the script, I will make a test directory of images to test later.

Phil Harvey

Yes, the BEGIN is in the exiftool script.

Which installer are you using?  The Mac installer puts stuff in /usr/local/bin/lib which is non-standard.  You may be better off using the Perl package if you want to write scripts using the ExifTool API -- that installer should put it somewhere in the perl @INC.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on September 13, 2024, 09:26:17 PMYou may be better off using the Perl package if you want to write scripts using the ExifTool API -- that installer should put it somewhere in the perl @INC.

This is where the problem is. They're not using the command line, they're using the API and Perl can't find the exiftool files.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype