harangzsolt33 has asked for the wisdom of the Perl Monks concerning the following question:

Right now I am using Lubuntu 23.04 x64 on an old DELL desktop computer. I installed Perl, and this is the first time I want to install a third-party module from CPAN. I want to create a Perl program with a graphical user interface, so I decided to download Prima.

I'm not sure how to do this, so if I remember correctly, I need to write: sudo apt-get install Prima

Well, that didn't work. It says, there's no such program.

Okay, then I go to the CPAN website and find Prima and click on download. It downloaded a file called Prima-1.70.tar.gz. Then I opened the terminal and extracted it and moved all of its contents to /usr/share/perl5 which is one of the paths that showed up in the @INC list when I executed: perl -e "print join('--', @INC);" Then I searched for the word "Prima" on PerlMonks and copied and pasted the first example program I saw. I saved this file on my desktop. I called it menutest.pl and then I added the line #!/usr/bin/perl -w in the first line. I made sure the file is executable. I open terminal and try to run it: perl menutest.pl, and this is what it says:

Can't locate Prima.pm in @INC (you may need to install the Prima module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.36.0 /usr/local/share/perl/5.36.0 /usr/lib/x86_64-linux-gnu/perl5/5.36 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.36 /usr/share/perl/5.36 /usr/local/lib/site_perl) at menutest.pl line 6. BEGIN failed--compilation aborted at menutest.pl line 6.

If you look at this list, the location where I copied Prima's files is right there in the list: /usr/share/perl5

If I go to /usr/share/perl5/Prima/examples, I see a bunch of pl files there. If I try to run any one of them (i.e. perl grid.pl), it gives me the same error message.

What did I do wrong?

Oh wait. Prima.pm is actually not where it's supposed to be. Ok. I moved the pm files from /usr/share/perl5/Prima/Prima to /usr/share/perl5/Prima and then I copied Prima.pm to /usr/share/perl5. All right. Now, perl says it can't locate a "loadable object." What does that mean?

Can't locate loadable object for module Prima in @INC (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.36.0 /usr/local/share/perl/5.36.0 /usr/lib/x86_64-linux-gnu/perl5/5.36 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.36 /usr/share/perl/5.36 /usr/local/lib/site_perl) at menutest.pl line 6. Compilation failed in require at menutest.pl line 6. BEGIN failed--compilation aborted at menutest.pl line 6.

Arrgh!

Replies are listed 'Best First'.
Re: How do I install a Perl module?
by hippo (Archbishop) on Oct 28, 2023 at 12:18 UTC
    What did I do wrong?

    You manually copied/moved a bunch of files around arbitrarily instead of actually installing the module. See A Guide to Installing Modules for how to do it properly.

    You may also need the non-perl prerequisites for Prima as has already been mentioned in this thread and in the Prima FAQ.


    🦛

Re: How do I install a Perl module?
by marto (Cardinal) on Oct 28, 2023 at 10:52 UTC

    If you want to install a cpan module, use cpan or perferibly cpanm. The page on metacpan has install instructions:

    cpanm cpanm Prima CPAN shell perl -MCPAN -e shell install Prima

    Running cpanm Prima resulted in success. The point of cpanm/cpan is to satisfy dependencies while installing modules properly. Unsurprisingly Tutorials, has a section dedicated to this. Personally I tend to leave the system perl alone and install my own using perlbrew.

    Update: not all modules are pure perl, so just copying things around won't always work.

      That's not reliably sufficient on a "bare" system. Prima needs runtimes and in particular development headers for some graphics libraries which cpanm won't install.

        Indeed, if you are missing the prereqs it will tell you, ** No image codecs found, I likely have them from building something else in the past.

      So, where can I get cpanm? If I say sudo apt-get install cpanm, it says there's no such program. I noticed that there's a cpanminus on Github. But I am not sure if cpanm is the same as cpanminus.

      https://github.com/miyagawa/cpanminus/tree/devel/App-cpanminus

      Am I looking at the right thing?

        I strongly recommend not messing with the system perl on Linux! Building your own perl can be done as non-root, allows you to use the latest Perl, and gives you the freedom to experiment and play around with things without risking breaking your system Perl.

        In case it's of use, this node (in the "Example: build perl v5.38 securely from source on Ubuntu" section) includes a complete example of building the latest Perl securely from source as non-root using App::cpanminus (and its cpanm command), followed by installing and uninstalling a CPAN module.

        👁️🍾👍🦟

        That's the one. Note that apt cpanminus will install that for you. The README is helpful, and provides other options/considerations, as mentioned previously building your own perl with perlbrew, should you wish to avoid playing with the system perl.

        So, where can I get cpanm?
        1. Go to MetaCPAN
        2. Type cpanm into the search box and hit return
        3. Click the first entry of the search results
        4. Click the Download link in the left panel

        🦛

Re: How do I install a Perl module?
by haj (Vicar) on Oct 28, 2023 at 10:25 UTC

    Short answer: The installation instructions in the README.md file cover Ubuntu.

    Long answer: Prima is not available from Ubuntu, and if it were, its package name would certainly obey the Debian naming convention and be named libprima-perl. If you download a module from CPAN for manual installation, you should always look in its root directory for installation instructions. Just copying the stuff to /usr/share/perl5 is not the way to install from CPAN and will fail for many modules. In particular, modules containing parts written in C (like Prima) will never work that way.

      Yes, it is a bit weird that no script exists to install Prima. I have a Brother printer, and when I wanted to install the drivers for linux, I went to the website, and they had a little install script for the Brother printers. I downloaded the script and executed it from the terminal, and it did everything to make the printer work. It was EASY. But the installation of Prima doesn't seem very easy. I mean it gave me all sorts of error messages at first. It did not find the libraries, so I installed them. Thank you for pointing me to README.md! Coming from Windows, the .md file extension did not seem familiar to me. If it had been README.txt I would have opened it for sure.

      I ran perl Makefile.PL and I did not have gcc installed the way Makefile expected it, so I had to create a symbolic link in /bin for the gcc compiler. After that, it ran okay. Next, I tried to issue the make command, but it did not exist, so I had to install make. Then I began the make process. While it was compiling, it did show 3 or 4 error messages in the source code, but it scrolled by so fast, I couldn't remember all of what I saw. One of the errors was regarding a function call to strlcpy() and it said it doesn't exist, did you mean to use strncpy() instead? Another error existed in a calculation, but I can't remember where I saw it.

      Anyway, I looked and saw that it actually installed Prima into this directory:

      /usr/local/lib/x86_64-linux-gnu/perl/5.36.0/Prima

      Then I tried some examples, and they worked. So, it looks like it's a success! But it could have been easier. Ahem.