Online Quotes

From GnuCash
Revision as of 23:27, 7 October 2024 by Fell (talk | contribs) (lang="console" highlight input lines to avoid "$"s)
Jump to: navigation, search
Installing Finance::Quote on macOS from a Terminal prompt

New security requirements for macOS 10.14.6 and 10.15.0 put an end to the FinanceQuote Update app. Users must now use Terminal.app to install Finance Quote.

sudo /Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update

The first time you run gnc-fq-update or cpan cpan will display some questions:

Loading internal logger. Log::Log4perl recommended for better logging

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes]

Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
[local::lib] sudo

Unless you're a perl expert and know differently, you should accept the default yes on the first question and select sudo on the second. That will invoke sudo for every install step, and so will sometimes stop and request your password to authenticate sudo.

Compiled binaries on Apple Silicon (aka M1, M2, etc.) processors can be native or Intel. The latter run under a special program called Rosetta2 and GnuCash may be one such program if you're using an x86_64 build. (Apple Silicon builds are available since GnuCash 5.8). The Perl binaries that Apple supplies are multi-architecture ("universal" in Apple-speak) but left to itself cpan will install only native binaries resulting in GnuCash not being able to use them. You can tell cpan to install Finance::Quote for Intel with

    arch -x86_64 /Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update

but that has risks: If cpan decides to update itself or if you use cpan for other purposes you can wind up with a mix of Apple Silicon and Intel binaries that can break your perl installation. It's better to set the environment variable ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' to get cpan to always make universal binaries. To do that for Finance::Quote only you can run

    ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' /Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update

but if you use perl for other things you might prefer to set ARCHFLAGS in you shell profile so that cpan always builds universal binaries.

If you've already run cpan or gnc-fq-update without having set ARCHFLAGS you may need to clean /Library/Perl/<perl-version>. There may be several versions in /Library/Perl especially if you've upgraded your macOS from previous versions instead of having a clean install or used the Migration Assistant to load a new Mac from an old one. The only one that matters is the one corresponding to the current version of /usr/bin/perl. To check that run

/usr/bin/perl --version

You can ignore any micro version numbers. A safe way to clean e.g. /Library/Perl/5.30 is

sudo mv /Library/Perl/5.30 /Library/Perl/saved-5.30
sudo mkdir /Library/Perl/5.30
sudo cp /Library/Perl/saved-5.30/AppendToPath /Library/Perl/5.30/

Once you've completed reinstalling all of your extra perl modules you can compare 5.30 and saved-5.30 to make sure you didn't miss anything. Once you're satisfied you can safely delete /Library/Perl/saved-5.30.

Note the last line in that procedure: /Library/Perl/5.xx/AppendToPath contains a single line, /System/Library/Perl/5.xx/Extras. If the file is missing or is missing that line then a lot of perl infrastructure is missing too and installing Finance::Quote will either take a long time while cpan installs all of those modules; it may fail altogether because certain C libraries or their headers (notably OpenSSL) aren't installed where cpan can find them. A normal installation of Finance::Quote will include only a few modules and provided you have a reasonable fast internet connection will take only 2-3 minutes. If it's taking longer check that AppendToTargets is installed and contains the right path. You can double-check it by printing the include-path variable @INC. Run either

perl -V | tail

or

perl -e 'print(join("\n", @INC), "\n");'

and check for /System/Library/Perl/Extras/5.xx and /System/Library/Perl/Extras/5.xx/darwin-thread-multi-2level are at the end of the list. If they're not clear </Library/Perl/5.xx</code using the procedure above and fix AppendToPath.

Note
macOS will not allow you to use cat to create or modify AppendToPath but you can use any plain text editor including TextEdit or nano.

Credit for the environment variable belongs to this Stack Overflow answer and it also provides more background. The procedure to clear out cpan-installed modules is from Bug 798928 comment 11.

The gnc-fq-update script always runs the macOS system Perl runtime (/usr/bin/perl), and disregards the Perl installed by package managers. Doing so ensures GnuCash, when launched from Finder, can locate Finance::Quote correctly.