Problems with using SFTP perl module - perl

I'm trying to use the SFTP module in Perl. My code looks likes this:
#!/usr/local/bin/perl5
use lib "/some_path/Net-SFTP-0.10/lib";
use lib "/some_path/Net-SSH-Perl-1.25/lib";
use lib "/some_path/Math-Pari-2.010709";
use Net::SFTP;
I get this error when running it:
Can't locate Math/Pari.pm in #INC
The Math-Pari-2.010709 directory contains the Pari.pm. I do not have permission to make a Math directory and put the Pari.pm file there. What can I do to fix this issue?

I use local::lib and set $PERL5LIB to $HOME/perl5 so building and installing missing modules is fairly easy:
% cpanm Math::Pari
--> Working on Math::Pari
Fetching http://www.cpan.org/authors/id/I/IL/ILYAZ/modules/Math-Pari-2.01080605.tar.gz ... OK
Configuring Math-Pari-2.01080605 ... OK
Building and testing Math-Pari-2.01080605 ...
Successfully installed Math-Pari-2.01080605
1 distribution installed
You'll need to install App::cpanminus by following the instructions at https://github.com/miyagawa/cpanminus which essentially are:
curl -L http://cpanmin.us | perl - App::cpanminus
After that with cpanm in your $PATH (here it is in $HOME/perl5/bin) installing modules in your own $HOME directory is a breeze.

Following the comments, I ended up using Net::SFTP::Foreign. It is sufficient to get stuff done, and fewer dependencies made life easier on me. Thanks for all the help!

Related

App::FatPacker on Windows

I have a script on Windows which uses multiple pure Perl modules from CPAN.
I am trying to ship this script without the need to reinstall those modules from CPAN using App::FatPacker.
I installed App::FatPacker ( up to date (0.010007) version ) on Portable Strawberry Perl 5.24 .
When I run the following command
fatpack pack myscript.pl > myscript.packed.pl
I get
syntax OK
but the fatlib is empty and when I run my script it fails.
I tried to use this script which does nothing but load Geo::IP::PurePerl
use strict;
use warnings;
use Geo::IP::PurePerl;
and run again this command :
fatpack pack myscript.pl > myscript.packed.pl
Then I ran myscript.packed.pl on another instance of Strawberry Perl 5.24, I get the following error:
Can't locate Geo/IP/PurePerl.pm in #INC (you may need to install the Geo::IP::PurePerl module
I tried to debug it by building step by step
The fatpack trace creates a trace list as expected, including Geo::IP::PurePerl
The fatpack packlists-for finished successfully but the fatlib is empty.
Any idea?
I would say that packlists-for isn't finding any .packlist files
The documentation for fatpack says this
packlists-for
$ fatpack packlists-for Module1 Module2 Module3
Searches your perl's #INC for .packlist files containing the .pm files for the modules requested and emits a list of unique packlist files to STDOUT.
These packlists will, in a pure cpan-installation environment, be all non-core distributions required for those modules.
Unfortunately most vendors strip the .packlist files so if you installed modules via e.g. apt-get you may be missing those modules; installing your dependencies into a local::lib first is the preferred workaround.
I think that's useful advice that may well fix your problem

#INC Perl- Can't locate Class/CSV.pm in #INC

I am currently trying to create/generate a CSV file using one of three classes:
use Class::CSV;
use Text::CSV;
use Text::CSV_XS;
Though when I try and run it, to check my code I come up with the same error message:
Can't locate Class/CSV.pm in #INC (#INC contains: C:/Per/site/lib C:/Perl/lib .) at C:\Users\<DIRECTORY> - <DIRECTORY>.file.pl line1
I have tried searching for the files though I haven't had any luck. Has anyone else come up against this problem? I have looking in the Directory and the CSV.pm file does exists.
Assuming that Class::CSV is installed on your system, your library search path is incomplete. (Your error message lists C:/Per/site/lib as a search lib, which looks like a typo for C:/Perl/site/lib, which you might want to look into.)
You need to locate the correct CSV.pm file where the library is located. For example, if it's found in:
C:/Perl/lib/foo/Class/CSV.pm
Then you have one of the following options.
Modify the environment for Perl or the invocation so that this is set (assuming my Windows skill haven't expired completely, someone feel free to edit and correct if I get the syntax wrong):
PERL5LIB=%PERL5LIB%;C:/Perl/lib/foo
You can use the -I option to perl to add the path:
perl -IC:/Perl/lib/foo my-app.pl
You can use the use lib command in the program itself to add the search path:
use lib 'C:/Perl/lib/foo';
use Class::CSV;
# etc.
You probably don't have these modules installed.
run this in your shell
perl -MCPAN -e shell
then run
install Class::CSV
I'm assuming that you found these classes on CPAN
You can simply run the following command
perl -MCPAN -e 'install Class::CSV'
to run
install Class::CSV in CPAN shell.

Building perl module gives metafile error

I'm working on installing a perl module (not using CPAN) on a Linux machine. When I run the command:
perl Build.PL
I get the following error:
ERROR: Missing required field 'dist_abstract' for metafile
Could not get valid metadata. Error is: Invalid metadata structure.
Errors: Missing mandatory field, 'abstract' (abstract) [Validation: 1.4],
value is an undefined string (abstract) [Validation: 1.4]
at /usr/local/share/perl5/Module/Build/Base.pm line 4559
Could not create MYMETA files
I've tried Googling bits and pieces of this error but haven't found any solutions. Just looking for a clue as to what might be causing this error.
Here's a link to a zip file containing the files required to install it:
https://oncourse.iu.edu/access/content/user/brilewis/Filemanager_Public_Files/DataDownloader.zip
First at all please make sure you have package Module::Build installed.
You need ungzip few gzipped files in this package. I don't realize why author gzipped them:
gzip -d *.gz
I really don't know why author archived each install file. It looks like some mistake to me.
Than you can install all dependencies (this module requires some):
./Build installdeps
And then finally install module itself:
./Build
./Build test
./Build install
However I must warn you that this module packaged in a bit strange way and there's no guarantee it works.
The NAME section of the module does not have a - in it, e.g.,
=head1 NAME
Foo::Bar implements a Foo framework.
will fail, but if you make it
=head1 NAME
Foo::Bar - implements a Foo framework.
then it will work.
Do you have root access on your machine? Can you use the cpan utility to build and install your module. Using cpan is fairly straight forward:
$ cpan
After that, it will do a lot of configuration, simply take the default values. When it finishes, it'll come to a cpan> prompt. All you have to do there is type this:
cpan> install Module::Name
Where Module::Name is the module you're trying to install. Check the CPAN archive to get the name of your module.
If there are any dependencies, CPAN will ask if you want to download and install those. Say Yes, and CPAN will install the dependencies, then your module.
Using cpan is the best way to install third party modules you find in the CPAN archive. It takes care of all the dependencies, testing, and building for you.
Try installing through CPAN, and then see if you still have your issues.

How do I use a dependency on a Perl module installed in a non-standard location?

I need to install two Perl modules on a web host. Let's call them A::B and X::Y. X::Y depends on A::B (needs A::B to run). Both of them use Module::Install. I have successfully installed A::B into a non-system location using
perl Makefile.PL PREFIX=/non/system/location
make; make test; make install
Now I want to install X::Y, so I try the same thing
perl Makefile.PL PREFIX=/non/system/location
The output is
$ perl Makefile.PL PREFIX=/non/system/location/
Cannot determine perl version info from lib/X/Y.pm
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- Test::More ...loaded. (0.94)
- ExtUtils::MakeMaker ...loaded. (6.54 >= 6.11)
- File::ShareDir ...loaded. (1.00)
- A::B ...missing.
==> Auto-install the 1 mandatory module(s) from CPAN? [y]
It can't seem to find A::B in the system, although it is installed, and when it tries to auto-install the module from CPAN, it tries to write it into the system directory (ignoring PREFIX). I have tried using variables like PERL_LIB and LIB on the command line, after PREFIX=..., but nothing I have done seems to work.
I can do make and make install successfully, but I can't do make test because of this problem. Any suggestions?
I found some advice at http://servers.digitaldaze.com/extensions/perl/modules.html to use an environment variable PERL5LIB, but this also doesn't seem to work:
export PERL5LIB=/non/system/location/lib/perl5/
didn't solve the problem.
The answer is local::lib, but you probably already know that :)
OK, the following prescription did it:
perl Makefile.PL --skipdeps --no-manpages PREFIX=/non/system/location INSTALLSITELIB=/non/system/location/lib INSTALLSITEBIN=/non/system/location/bin INSTALLMAN1DIR=/non/system/location/man/man1 INSTALLMAN3DIR=/non/system/location/man/man3
This is just "monkey see monkey do" but now make test works.
The --skipdeps option here suppresses a convenient feature/exasperating problem with Module::Install where it tries to use CPAN.pm to download missing modules.
The --no-manpages is supposed to stop it installing man pages but it doesn't work.
Because this is the top link i thought i'd update with my experience (which has taken a while to get working, hence updating the 7 year old post).
first run perl -le 'print join $/, #INC'
add (note, no / at the end!!)
export PERL5LIB=/nonstddir/scripts/modules/lib/site_perl:/nonstddir/scripts/modules/lib
run perl -le 'print join $/, #INC' make sure the new dirs are added. this makes it work. if you add a / at the end of the path, the INC entry will look weird and wrong. Mine had a // in the middle.
When done and working, mine looks like
/nonstddir/scripts/modules/lib/site_perl/5.8.4/sun4-solaris-64int
/nonstddir/scripts/modules/lib/site_perl/5.8.4
/nonstddir/scripts/modules/lib/site_perl
/nonstddir/scripts/modules/lib/sun4-solaris-64int
/nonstddir/scripts/modules/lib
/usr/perl5/5.8.4/lib/sun4-solaris-64int
/usr/perl5/5.8.4/lib
/usr/perl5/site_perl/5.8.4/sun4-solaris-64int
/usr/perl5/site_perl/5.8.4
/usr/perl5/site_perl
/usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int
/usr/perl5/vendor_perl/5.8.4
/usr/perl5/vendor_perl

Adding a library to the #INC array in perl

I am running a script which requires the Curl.pm lib in order to work. I used YUM to install the library and now I am trying to have my script use it, but I keep getting the error
Can't locate WWW/Curl.pm in #INC (#INC contains: /usr/lib64/perl5/site_perl/5.8.6/x86_...
When I type the following in the command line:
rpm -ql curl
I get:
/usr/bin/curl
/usr/lib64/libcurl.so.3
/usr/lib64/libcurl.so.3.0.0
/usr/share/doc/curl-7.13.1
/usr/share/doc/curl-7.13.1/BUGS
/usr/share/doc/curl-7.13.1/CHANGES
/usr/share/doc/curl-7.13.1/COPYING
/usr/share/doc/curl-7.13.1/FAQ
...
/usr/share/man/man1/curl.1.gz
/usr/bin/curl
/usr/lib/libcurl.so.3
/usr/lib/libcurl.so.3.0.0
/usr/share/doc/curl-7.13.1
/usr/share/doc/curl-7.13.1/BUGS
/usr/share/doc/curl-7.13.1/CHANGES
... etc.
Which one of the paths above needs to be included in my #INC directory? I had thought that the code below would solve the problem when placed at the top of my script, but I am still getting the same error #INC error.
BEGIN {
unshift(#INC, '/usr/lib/libcurl.so.3');
use WWW::Curl;
}
When I type
cpan> i /WWW::curl/
I get the following list below. I'm still stumped. I want to use WWW::curl and I don't know which of the paths below (or above) to add to #INC ! It looks like it's already installed. What do I do from here?
cpan> i /WWW::curl/
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
Database was generated on Mon, 30 Nov 2009 02:55:47 GMT
Module WWW::Curl (S/SZ/SZBALINT/WWW-Curl-4.09.tar.gz)
Module WWW::Curl::Easy (S/SZ/SZBALINT/WWW-Curl-4.09.tar.gz)
Module WWW::Curl::Form (S/SZ/SZBALINT/WWW-Curl-4.09.tar.gz)
Module WWW::Curl::Multi (S/SZ/SZBALINT/WWW-Curl-4.09.tar.gz)
Module WWW::Curl::Share (S/SZ/SZBALINT/WWW-Curl-4.09.tar.gz)
Module WWW::Curl::Simple (A/AN/ANDREMAR/WWW-Curl-Simple-0.05.tar.gz)
Module WWW::Curl::Simple::Request (A/AN/ANDREMAR/WWW-Curl-Simple-0.05.tar.gz)
7 items found
You have installed the curl library. To install the WWW::Curl module do this:
yum install perl-WWW-Curl
You installed curl which is not the same thing as WWW::Curl.
You need to install the Perl module WWW::Curl. You should first search your OS specific package repositories for the module. If you cannot find it there, use cpanm to install it:
$ cpanm WWW::Curl
See also perldoc perlmodinstall.
I am going to ignore that chaos that I see and simply answer the question:
You don't add libraries to #INC, you add directories. The directories you add contain Perl modules, i.e. *.pm files.
To do that, you simply use use lib. If the directory you want to add is /foo/bar:
use lib qw| /foo/bar |;