Using Exiftool from Ruby

Started by perplexed, February 19, 2021, 07:49:57 AM

Previous topic - Next topic

perplexed

I'm attempting to use Exiftool with Ruby, and cannot get anything working.

I've asked on https://stackoverflow.com/questions/66194550/installation-of-ruby-exiftool-rb and https://github.com/exiftool-rb/exiftool_vendored.rb/issues/12 and had no responses, but further investigation shows this is perhaps more Exiftool or Perl related anyway.

My setup is Windows 10 with WSL1, which is Ubuntu 20.04 LTS and a Ruby environment using Bitnami Rubystack 2.7.2-1. I have installed Exiftool both within and outside the rubystack environment. Both versions work fine from either command line. I cannot call either version from Ruby, either using a gem or by a system or %x() call.  Gem installation was unproblematic. I've never had a similar problem with any other Ruby gem or running anything else via system calls.

I had this problem last year on a different PC with a similar installation, but different versions of everything. At the time I asked Bitnami support but they bailed saying they don't support WSL.  I made a workround by shelling into Windows and running Exiftool for Windows, because that was the only way I could get it to work.  This time I'd like to resolve the issue properly if possible.

I have tried two different gems, exiftool_vendored (which packages another gem exiftool-rb with a full version of Exiftool) and mini_exiftool which uses what it finds on the path. So I have two installed versions of the tool, at /usr/bin/exiftool and at /home/knot/rubystack/ruby/lib/ruby/gems/2.7.0/gems/exiftool_vendored-12.18.0/bin/exiftool. Both work from the command line but not when called from within Ruby.  They produce the same error, for example

knot@Pond:~/rubystack/projects/dupes which exiftool
/usr/bin/exiftool
knot@Pond:~/rubystack/projects/dupes exiftool -ver
11.88
knot@Pond:~/rubystack/projects/dupes irb
irb(main):001:0> system("which exiftool")
/usr/bin/exiftool
=> true
irb(main):002:0> system("exiftool -ver")
Can't load '/home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/auto/File/Glob/Glob.so' for module File::Glob: /home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/auto/File/Glob/Glob.so: undefined symbol: PL_env_mutex at /home/knot/rubystack/perl/lib/5.32.0/XSLoader.pm line 93.
at /home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/File/Glob.pm line 66.
Compilation failed in require at /usr/bin/exiftool line 919.
BEGIN failed--compilation aborted at /usr/bin/exiftool line 919.
Undefined subroutine &main::SetWindowTitle called at /usr/bin/exiftool line 333.
END failed--call queue aborted at /usr/bin/exiftool line 919.
=> false


All other Exiftool commands, both via system calls or from the gems, fail with various error messages.  That one is recurrent and seems the most informative although I don't understand it.

As it appears to be Perl related I'll add
irb(main):001:0> system("which perl")
/home/knot/rubystack/perl/bin/perl
=> true
irb(main):002:0> system("perl -ver")
This is perl 5, version 32, subversion 0 (v5.32.0) built for x86_64-linux-thread-multi


but the base WSL install, before running the rubystack is
knot@Pond:~ perl -ver
This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi


Is that relevant? I'm afraid I don't know, I'm hoping someone with better understanding can disentangle what's happening and perhaps point at a way forward.

Thanks for reading, sorry it's rather wordy but I don't know which bits of context should be omitted.

Phil Harvey

I've had similar problems with other projects.  The problem always comes down to different environment variables when you launch the app differently.  This is why I hate environment variables, and why ExifTool doesn't use them.  But unfortunately Perl does.

I suggest comparing your command-line environment to the environment of your system() function.  You should be able to do this by executing the printenv command from each method.

Also, you should maybe check the Perl include path: perl -e 'print "@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 ($).

perplexed

perl -e 'print "@INC"' is the same both ways.

I use Bitnami to set up the environment Ruby sees because I wouldn't know where to start.

This is the most obvious line in the Ruby environment, and exporting it to the command shell causes the same error.

knot@Pond:~/rubystack/projects exiftool -ver
11.88
knot@Pond:~/rubystack/projects PERL5LIB=/home/knot/rubystack/git/lib/site_perl/5.32.0:/home/knot/rubystack/perl/lib/5.32.0:/home/knot/rubystack/perl/lib/site_perl/5.32.0:/home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi:/home/knot/rubystack/perl/lib/site_perl/5.32.0/x86_64-linux-thread-multi
knot@Pond:~/rubystack/projects export PERL5LIB
knot@Pond:~/rubystack/projects exiftool -ver
Can't load '/home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/auto/File/Glob/Glob.so' for module File::Glob: /home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/auto/File/Glob/Glob.so: undefined symbol: PL_env_mutex at /home/knot/rubystack/perl/lib/5.32.0/XSLoader.pm line 93.
at /home/knot/rubystack/perl/lib/5.32.0/x86_64-linux-thread-multi/File/Glob.pm line 66.
Compilation failed in require at /usr/bin/exiftool line 919.
BEGIN failed--compilation aborted at /usr/bin/exiftool line 919.
Undefined subroutine &main::SetWindowTitle called at /usr/bin/exiftool line 333.
END failed--call queue aborted at /usr/bin/exiftool line 919.
knot@Pond:~/rubystack/projects



Phil Harvey

So there's the answer.  You should be able to set up Ruby so it uses the same environment that works from the command line.

- 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 ($).

perplexed

Hmm, I see what you're saying but I have no idea what the wider consequences of that would be.  I'll have a play and see what happens.  If all else fails I can go back to using the Windows version as a workround.

Thanks for your help.

MtnBiker

Check out https://github.com/janfri/mini_exiftool which is well supported. Works well.