Python syntax error running freshly installed `meld` - centos

I'm installing meld as described here:
sudo yum install intltool itstool gir1.2-gtksource-3.0 libxml2-utils
However, when I try to run meld this error appears:
File "/usr/bin/meld", line 47
print _("Meld requires %s or higher.") % modver
^
And indeed /usr/bin/meld has this code:
def missing_reqs(mod, ver):
modver = mod + " " + ".".join(map(str, ver))
print _("Meld requires %s or higher.") % modver
sys.exit(1)
I'm on CentOS 6.7, Python version 3.3.5.
Could you advise on what I'm doing wrong here?
EDIT:
Here's the command line, verbatim:
$ meld
File "/usr/bin/meld", line 47
print _("Meld requires %s or higher.") % modver
^
SyntaxError: invalid syntax
Here is a portion of meld script:
import sys
if "--pychecker" in sys.argv:
sys.argv.remove("--pychecker")
import os
os.environ['PYCHECKER'] = "--no-argsused --no-classattr --stdlib"
#'--blacklist=gettext,locale,pygtk,gtk,gtk.keysyms,popen2,random,difflib,filecmp,tempfile'
import pychecker.checker
#
# i18n support
#
sys.path[0:0] = [ "/usr/share/meld"
]
import paths
import gettext
_ = gettext.gettext
gettext.bindtextdomain("meld", paths.locale_dir())
gettext.textdomain("meld")
# Check requirements: Python 2.4, pygtk 2.8
pyver = (2,4)
pygtkver = (2,8,0)
def missing_reqs(mod, ver):
modver = mod + " " + ".".join(map(str, ver))
print _("Meld requires %s or higher.") % modver
sys.exit(1)
if sys.version_info[:2] < pyver:
missing_reqs("Python", pyver)

print is a statement in python2 just like your script has:
print _("Meld requires %s or higher.") % modver
But you are interpreting the script using python3 which does not have print statement rather has print() function.
You can try to replace all print with print() with a hope that nothing else breaks, which is not a good solution anyway.
Better just install python2:
sudo yum install python2
and use python2 as the interpreter.

Related

Unexpected behavior with CPAN_JSON

Trying to use CPAN_JSON in the following way:
my $integer = 200;
JSON->new->allow_nonref->encode($integer);
and get the following error;
Can't locate object method "FLAGS" via package "B::IV"
Coming from:
https://metacpan.org/source/MAKAMAKA/JSON-2.90/lib/JSON/backportPP.pm#L408
Running perl 5.8, I thought B Core packages are always included. Any ideas why this is happening?
Edit:
perl -v | grep This
This is perl, v5.10.1
perl -MJSON::backportPP -le'print $JSON::backportPP::VERSION || $JSON::PP::VERSION'
2.27200
perl -mB -le'my $value = 1; my $b_obj = B::svref_2object(\$value); print $b_obj->FLAGS;'
266498

perl throws error "length() used on #array (did you mean "scalar(#array)"?) at /usr/lib64/perl5/IO/Compress/Zlib/Extra.pm line 198."

The vsphere perl sdk version 5.5 is installed on centos 7 64 bit machine
The following simpleclient.pl(https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.perlsdk.pg.doc/viperl_modscripts.4.2.html#990705) script throws error "length() used on #array (did you mean "scalar(#array)"?) at /usr/lib64/perl5/IO/Compress/Zlib/Extra.pm line 198." on centos-7 64 bit machine.
root#localhost vsphere_perl_exp]# cat simpleclient.pl
#!/usr/bin/perl
use strict;
use warnings;
use VMware::VIRuntime;
my %opts = (
entity => {
type => "=s",
variable => "VI_ENTITY",
help => "ManagedEntity type: HostSystem, etc",
required => 1
},
);
Opts::add_options(%opts);
Opts::parse();
Opts::validate();
Util::connect();
# Obtain all inventory objects of the specified type
my $entity_type = Opts::get_option('entity');
my $entity_views = Vim::find_entity_views(
view_type => $entity_type);
[root#localhost vsphere_perl_exp]# perl --version
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 25 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Running perl with debug option stops at line 11,
[root#localhost vsphere_perl_exp]# perl -d ./simpleclient.pl --server 15.218.113.152 --username root --password 'secret' --entity HostSystem
Loading DB routines from perl5db.pl version 1.37
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(./simpleclient.pl:6): my %opts = (
main::(./simpleclient.pl:7): entity => {
main::(./simpleclient.pl:8): type => "=s",
main::(./simpleclient.pl:9): variable => "VI_ENTITY",
main::(./simpleclient.pl:10): help => "ManagedEntity type: HostSystem, etc",
main::(./simpleclient.pl:11): required => 1
DB<1> main::(./simpleclient.pl:14): Opts::add_options(%opts);
DB<1>
I am newbie to perl, How to debug this script?
It's not an exception being thrown; it's a warning being printed.
IO::Compress::Zlib::Extra contained the code
for (my $ix = 0; $ix <= length(#$data) -1 ; $ix += 2)
It was fixed in 2.042 (Nov 17th, 2011)
for (my $ix = 0; $ix <= #$data -1 ; $ix += 2)
The change log references tickets 72329 and 72505, the first of which shows what effect the bug has. This instance of the bug is rather harmless save for the annoyance of seeing the message when using newer versions of Perl.
To upgrade:
sudo cpan IO::Compress::Zlib::Extra
To get the length of an array:
my $length = scalar #array;
To get the length of a string:
my $length = length("my string");
Hope this helps.

Does Perl's Safe understand new features?

I'm playing with the Safe module for inclusion in Mastering Perl. Versions before v5.16 (the earliest supported version) doesn't seem to understand new keywords. Am I missing something?
say works with v5.16 and later
use v5.10;
use Safe;
say "Running $0 under $^V with Safe ", Safe->VERSION;
my $compartment = Safe->new;
$compartment->permit( ':base_io', ':load' );
my $code =<<"CODE";
use v5.10;
say "Hello Safe!";
CODE
$compartment->reval( $code ) or do {
my $error = $#;
warn "Safe compartment error! $#";
};
This code runs as I expect under v5.18 and v5.16, the two officially supported versions of Perl:
% perl5.18.0 safe.pl
Running safe.pl under v5.18.0 with Safe 2.35
Hello Safe!
% perl5.16.3 safe.pl
Running safe.pl under v5.16.3 with Safe 2.35
Hello Safe!
It doesn't work prior to v5.16 since it doesn't think the say keyword is valid:
% perl5.14.4 safe.pl
Running safe.pl under v5.14.4 with Safe 2.35
String found where operator expected at (eval 5) line 2, near "say "Hello Safe!""
(Do you need to predeclare say?)
Safe compartment error! syntax error at (eval 5) line 2, near "say "Hello Safe!""
% perl5.12.3 safe.pl
Running safe.pl under v5.12.3 with Safe 2.35
String found where operator expected at (eval 5) line 2, near "say "Hello Safe!""
(Do you need to predeclare say?)
Safe compartment error! syntax error at (eval 5) line 2, near "say "Hello Safe!""
% perl5.10.1 safe.pl
Running safe.pl under v5.10.1 with Safe 2.35
String found where operator expected at (eval 5) line 2, near "say "Hello Safe!""
(Do you need to predeclare say?)
Safe compartment error! syntax error at (eval 5) line 2, near "say "Hello Safe!""
state doesn't work but breaks differently
With state it's different.
use v5.10;
use Safe;
say "Running $0 under $^V with Safe ", Safe->VERSION;
my $compartment = Safe->new;
$compartment->permit( ':base_io', ':load' );
my $code =<<'CODE';
use v5.10;
print "Hello Safe!\n";
foo();
sub foo {
state $n = 0;
print "n is $n\n";
}
CODE
$compartment->reval( $code ) or do {
my $error = $#;
warn "Safe compartment error! $#";
};
v5.18 and v5.16 think state is a syntax error:
% perl5.18.0 safe.pl
Running safe.pl under v5.18.0 with Safe 2.35
Hello Safe!
n is 0
% perl5.16.3 safe.pl
Running safe.pl under v5.16.3 with Safe 2.35
Hello Safe!
n is 0
Before those versions, I think it's treating state as an indirect method:
% perl5.14.4 safe.pl
Running safe.pl under v5.14.4 with Safe 2.35
Hello Safe!
Safe compartment error! Can't call method "state" on an undefined value at (eval 5) line 5.
given
given has the same problem:
use v5.10;
use Safe;
say "Running $0 under $^V with Safe ", Safe->VERSION;
my $compartment = Safe->new;
$compartment->permit( ':base_io', ':load' );
my $code =<<'CODE';
use v5.10;
print "Hello Safe!\n";
my $foo = 'Buster Bean';
given( $foo ) {
when( /Buster/ ) { print "Buster\n" }
}
CODE
$compartment->reval( $code ) or do {
my $error = $#;
warn "Safe compartment error! $#";
};
It works just fine in v5.16 and v5.18:
% perl5.18.0 safe.pl
Running safe.pl under v5.18.0 with Safe 2.35
given is experimental at (eval 5) line 4.
when is experimental at (eval 5) line 5.
Hello Safe!
Buster
But breaks in earlier versions:
% perl5.14.4 safe.pl
Running safe.pl under v5.14.4 with Safe 2.35
Safe compartment error! syntax error at (eval 5) line 4, near ") {"
It's possible to use bisecting tool to check when certain piece of code started working. One is included, if you clone entire Perl repository. This allows to check when it started to work.
~/perl> Porting/bisect.pl --expect-fail --start=v5.14.0 --end=v5.16.3 -e '
use v5.10;
use Safe;
say "Running $0 under $^V with Safe ", Safe->VERSION;
my $compartment = Safe->new;
$compartment->permit( ":base_io", ":load" );
my $code =<<"CODE";
use v5.10;
say "Hello Safe!";
CODE
$compartment->reval( $code ) or do {
my $error = $#;
warn "Safe compartment error! $#";
exit 1;
};
'
After doing that, you get the result.
7d69d4a61be1619f90910462eac42234c874712e is the first bad commit
commit 7d69d4a61be1619f90910462eac42234c874712e
Author: Father Chrysostomos <sprout#cpan.org>
Date: Thu Dec 15 16:26:16 2011 -0800
Disable $[ under 5.16
This adds the array_base feature to feature.pm
Perl_feature_is_enabled has been modified to use PL_curcop, rather
than PL_hintgv, so it can work with run-time hints as well.
(PL_curcop holds the current state op at run time, and &PL_compiling
at compile time, so it works for both.) The hints in $^H are not
stored in the same place at compile time and run time, so the FEATURE_IS_ENABLED macro has been modified to check first whether
PL_curop == &PL_compiling.
Since array_base is on by default with no hint for it in %^H, it is
a ‘negative’ feature, whose entry in %^H turns it off. feature.pm
has been modified to support such negative features. The new FEATURE_IS_ENABLED_d can check whether such default features
are enabled.
This does make things less efficient, as every version declaration
now loads feature.pm to disable all features (including turning off
array_base, which entails adding an entry to %^H) before loading the
new bundle. I have plans to make this more efficient.
:100644 100644 e96e6608641a33838158a54cb0ac2402c716e848 3b81d3fc286480be3512864b43f3c9230fd1c376 M embed.fnc
:040000 040000 7f9483dd9d2f290810866ad40810461398385515 e1d43bd8aa24bec1d6b5f80a1f36f6787fb70d32 M ext
:100644 100644 2af41a87c417a2afded5c9f55bd0a69bcf71db80 37a1bd9510eb5064d052fb00b68a0e7eec3df716 M gv.c
:040000 040000 9d82bf63a49734aec1e01c5da6362c3dec7e1a22 2b12bd8c206ae14fc819fbb781cdb2b09c1a9c95 M lib
:100644 100644 c55ca63a5819c32c747279ddcc698653dc8eca6f 3432dfe5c4c7b568712a9f0f31177695528892e4 M mg.c
:100644 100644 313087d34a4135e1854b4f00ab58b71d687a32e1 812ece2bb1757489865e36dec0ceeaa8d6c86168 M op.c
:100644 100644 e203dfe1941e7c3e13cdf6b68e509339258229bf ef3d4efec6604738d6beded3ff16d9a1ab73c465 M perl.h
:100644 100644 92befdac8afebe578740e84ca24ca46a091b072e eec052f413638d1efba00c81f423a68d1a4f984e M proto.h
:040000 040000 9deb7ece55f230bcf0e0bb83a5e1646e05770db2 d425283f05fb825181a2b3836ff3ce2570821500 M t
:100644 100644 2c29c582e2a1c2ba6aeefe56368a383785b27830 2f395d458da5941b49552d85bbf52b1070b5b32e M toke.c
bisect run success
That took 1921 seconds
The problem is that it was an accidentally fixed bug. If you take a look at diff for toke.c, you can notice that the old version took features from PL_hintgv, but the new version uses PL_curcop. The difference between these is that PL_hintgv contains compile time unit settings. PL_curcop however, contains current settings. While being in Safe, use feature saves to wrong place.
The problem is that PL_hintgv checks current compilation unit. When dealing with Safe, it's meaningless empty hash, because of the hacking the module does to work. PL_curcop however checks current scope - so it works well with Safe.
Now for workarounds. One exists, but it involves specifying settings by using eval. As eval sets compilation unit, you can use it to specify settings you want. It won't let user change the settings, but will let provide you some settings for evaluated code.
For example, if you change $compartment->reval( $code ) with eval '$compartment->reval( $code )' in your code, it will start working, as eval made a new compilation unit, and your code has use v5.10; in heading (eval copies use v5.10 from it). It's an awful hack nevertheless …

Adding sys/ioctl.ph to Perl headers

I need to use sys/ioctl.ph and it's not included in the perl version (5.12.3) shipped with my slackware distribution.
I did the following:
cd /usr/include
h2ph sys/ioctl.ph
cd /usr/lib64/perl5/site_perl/5.12.3/x86_64-linux-thread-multi/
mkdir sys
mv ioctl.ph sys
Now the perl interpreter doesn't complain about the sys/ioctl.ph, but this is the error I get:
Illegal declaration of subroutine Functions::ServerSocket::__INT16_C at /usr/lib64/perl5/site_perl/5.12.3/x86_64-linux-thread-multi/_h2ph_pre.ph line 164.
This is what there's in the file that causes the error at line 164:
unless (defined &__INT16_C(c)) { sub __INT16_C(c)() { &c } }
I don't know where to start. Functions::ServerSocket is one of my module, but I don't have any function like that in my file.
The __INT16_C macro on your platform is probably simple, e.g.,
#define __INT16_C(c) c
Replace the code on line 164 with
eval 'sub __INT16_C {
my($c) = #_;
eval q($c);
}' unless defined (&__INT16_C);
which is what other versions of h2ph generate.

Perl script compilation into .exe error

I am trying to create a .exe in perl. It works fine until I try to compile it into an exe. I am using Komodo IDE 5. I have posted my script and the error below. I have added the modules, LWP::UserAgent, NET, and Google::Voice and it still doesnt work. I use perlapp to create the .exe
#!/usr/bin/perl -w
use strict;
use warnings;
use Google::Voice;
use Date::Calc qw(Delta_Days);
use Net::Twitter;
#Set Days
my #today = (localtime)[5,4,3];
$today[0] += 1900;
$today[1]++;
my #RT = (2012, 7, 7);
my $days = Delta_Days(#today, #RT);
#Get Quotes and Phone Numbers
open FILE, "c:/Countdown/countdownNumbers.txt" or die "Couldn't open file: $!";
my $numbers = join("", <FILE>);
close FILE;
open FILETWO, "c:/Countdown/Quotes.txt" or die "Couldn't open file: $!";
my $quotes = join("", <FILETWO>);
close FILETWO;
#Create Arrays and Lengths
my #numbersArray = split(/[\n\r\l]+/, $numbers);
my #quotesArray = split(/[\n\r\l]+/, $quotes);
my $length = #numbersArray;
my $QuotesLength = #quotesArray;
#Send Text Message
for(my $i = 0; $i < $length; $i++){
my $g = Google::Voice->new->login('secret', 'secret');
$g->send_sms($numbersArray[$i] => " Countdown\nDays Left: " . $days . "\n Quote:\n" . $quotesArray[0]);
}
#Send Twitter Message
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => 'secret',
consumer_secret => 'secret',
access_token => 'secret',
access_token_secret => 'secret'
);
my $result = $nt->update($days .' Days left!');
$result = $nt->update('Quote: ' . $quotesArray[0]);
#Rewrite the file and close it
open FILETWO, ">c:/Countdown/Quotes.txt";
for(my $i = 1; $i < $QuotesLength; $i++){
print FILETWO $quotesArray[$i] . "\n";
}
close FILETWO;
errors
Algorithm\Diff\XS.pm:
error: Can't locate Algorithm\Diff\XS.pm
refby: C:\Perl\site\lib\Array\Diff.pm line 7
Date\Calc\XS.pm:
error: Can't locate Date\Calc\XS.pm
refby: C:\Perl\lib\Date\Calc.pm line 26
I18N\Langinfo.pm:
error: Can't locate I18N\Langinfo.pm
refby: C:\Perl\lib\Encode\Locale.pm line 51
JSON\PP58.pm:
error: Can't locate JSON\PP58.pm
refby: C:\Perl\lib\JSON\PP.pm
Net.pm:
error: Can't locate Net.pm
refby: perlapp --add Net::
Can't locate Mojo/EventEmitter.pm in #INC (#INC contains:) at /<C:\Users\Chris\Desktop\Countdown\RT.exe>Mojo/Base.pm line 32.
BEGIN failed--compilation aborted at /<C:\Users\Chris\Desktop\Countdown\RT.exe>Mojo/UserAgent.pm line 2.
BEGIN failed--compilation aborted at /<C:\Users\Chris\Desktop\RTCountdown\RT.exe>Google/Voice.pm line 6.
BEGIN failed--compilation aborted at RT.pl line 4.
Compiling perl script into exe file is not so straight-forward, I'm afraid. ) Check this discussion at Perlmonks for details.
From what you've quoted it seems that you might start fixing that with installing additional modules: Algorithm::Diff::XS, Date::Calc::XS, etc.
If you use latest version of perlapp, send this error to ActiveState support.
Temporarily you can use PAR::Packer instead of perlapp. Install PAR::Packer with cpan shell (ppm may not work). Then run
pp -c t1.pl
It will create a.out. If it would not work, install Module::ScanDeps from svn: http://svn.openfoundry.org/par/Module-ScanDeps/trunk/ - I fixed a couple of possible problems for your program.
I never used perlapp, but it may have command line switches to provide a list of modules to include.
I have downloaded Langinfo.pm from http://search.cpan.org/src/RJBS/perl-5.16.1/ext/I18N-Langinfo/Langinfo.pm to C:\Perl\lib\I18N and it works.
Komodo IDE, version 6.1.3
Perl Dev Kit Pro v9.1.1.
ActivePerl-5.14.2.1402-MSWin32-x86-295342