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

I am on Linux.
I've installed Tk with cpan
cpan install Tk
Everything installed correctly.
Then I run my program, that requires Tk, it shows the following error:
Can't locate Tk.pm in @INC (you may need to install the Tk module) (@I +NC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /u +sr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/ +share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 +/usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /m +nt/igor/bin/fdupes-gui.pl line 71.
I also tried to run cpan with sudo and installing Tk from sudoed cpan, It also successfully installed, but the program still gives me an error.
Then, I've found on the internet, that I can try to do:
cpan -i Tk
I tried both with sudo and without, also, I've tried to explicitly install it from root. Every time, it installs correctly, but the program keeps saying, that Tk.pm was not found. I entered cpan and tried to check installed Tk for updates with both ways of cpan, i.e. sudoed and regular:
r Tk
It gave me:
All modules are up to date for Tk
Then, I searched the common denominated folders from the list of given folders in the error above, i.e.:
find /etc /usr -iname '*Tk*.pm'
I've found it in:
/usr/local/lib/x86_64-linux-gnu/perl/5.20.2/
I've checked, none of the folders, that perl looks for libs doesn't match this one:
/etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base
I checked my perl version with:
perl -v
It gave me:
v5.22.1
I feel, that somehow, I need to tell cpan, that I have a v5.22.1 perl version and not 5.20.2, so it installs module in the correct folder. How can I do it? Or how can I fix this?

Solved:

While troubleshooting, I didn't find the root of evil on how to resolve the issue, but found out, that Ubuntu has a 'perl-tk' package. I've tried to install it. I don't know, honestly, what has changed, but my program started launching and working.

Replies are listed 'Best First'.
Re: Can't get Tk.pm to work
by marto (Cardinal) on Jan 26, 2018 at 11:00 UTC

    "I feel, that somehow, I need to tell cpan, that I have a v5.22.1 perl version and not 5.20.2, so it installs module in the correct folder. How can I do it? Or how can I fix this?"

    If you have multiple version of perl installed, each perl will have a version of cpan.

    marto@laptop:~$ which cpan /usr/bin/cpan

    Simply calling cpan Module::Name will invoke the first cpan in your PATH environment variable. Either provide the full path to cpan for the version of perl you want to install modules to (/app/perl26/bin/cpan Module::Name) or alter your PATH, giving precedence to the directory containing your target Perl installation. Also, consider using cpanm over cpan, it's faster.

      No, I don't have mutiple versions of perl. It's just updates automatically from ubuntu's repository.
      which cpan just shows:
      /usr/bin/cpan

        If as you say perl -v reports v5.22.1 but cpan is installing to /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/ it looks as though a Ubuntu has done something weird, which wouldn't be unheard of, for example. Do you have a #!/usr/local/bin/perl if so which version? Did you try using cpanm?

        My preference, for an easy life, is to install my own version of perl elsewhere, and leave the system one alone. A custom install has resulted in fewer headaches. See also perlbrew.

        Forgive my skepticism. You can confirm or refute this easily enough with locate -r /bin/perl$.

        You could also say which version of ubuntu you have installed so we can determine which perl is the interloper.

Re: Can't get Tk.pm to work
by shmem (Chancellor) on Jan 27, 2018 at 10:34 UTC
    I've installed Tk with cpan

    Why? there's a prebuilt perl-tk package in the ubuntu repository. As for Ubuntu 16.04.3 LTS:

    qwurx [shmem] ~> dpkg -l perl-tk Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/T +rig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=================-=============-=============-==================== +==================== ii perl-tk 1:804.033-1bu amd64 Perl module providin +g the Tk graphics li

    Since you are using the system perl, you should use the packages provided by your systems package manager

    user@system:~$ sudo apt-get install perl-tk

    and install via cpan/cpanm only if you absolutely need a different version.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Can't get Tk.pm to work
by Anonymous Monk on Jan 27, 2018 at 09:00 UTC
    Run env | grep PERL. Do you have a forgotten PERL_M?_OPT environment variable somewhere pointing to /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/? Is there anything fishy in ~/.cpan/CPAN/MyConfig.pm? (both for your user and superuser since you use sudo instead of setting up a local library)
Re: Can't get Tk.pm to work
by MorayJ (Beadle) on Jan 26, 2018 at 11:25 UTC

    Fixing your cpan would be the answer as above, but you can use the following to add an extra directory (or more) for your script to access modules not in your usual path: http://perldoc.perl.org/lib.htm

      "Fixing your cpan would be the answer as above, but you can use the following to add an extra directory (or more) for your script to access modules not in your usual path: http://perldoc.perl.org/lib.htm"

      cpan isn't broken, and doesn't require fixing. Note that your suggestion introduces the binary incompatibility problem.

      As a side note What shortcuts can I use for linking to other information?, [doc://lib] -> lib.

      the http://perldoc.perl.org/lib.htm url resolves to 404

        Should be, .html, perlmonks takes care of all this for you via [doc://lib] -> lib.

        the http://perldoc.perl.org/lib.htm url resolves to 404

        it works for me, maybe you need to try again?

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Re: Can't get Tk.pm to work [SOLVED]
by j8a (Initiate) on Feb 20, 2019 at 19:07 UTC
    Hi, I run sudo apt install perl-tk on Ubuntu (KDE-NEON) and the problem was fixed. Regards and many thank for the usefull information.