how can i specify the version of python that perl's inline::python module is using?

  • Last Update :
  • Techknowledgy :

You link with desired version during the installation of the module. See Makefile.PL:

# === === === === === === === === === === === === === === === === === === === === === === === === === =
   # What python are we going to
try ?
# === === === === === === === === === === === === === === === === === === === === === === === === === =
   my @pythons;
my $sep = $ ^ O eq 'MSWin32' ? ";" : ":";
for $p(split / $sep / , $ENV {
   PATH
}) {
   $p = ~s / ^ ~/$ENV{HOME}/;
   $p. = "/python";
   push @pythons, {
      path => $p
   }
   if -f $p && -x $p;
}

# Keep them in PATH order.
# @pythons = sort {
   $a - > {
      path
   }
   cmp $b - > {
      path
   }
}
@pythons;

my $num = 1;
print "Found these python executables on your PATH:\n";
print $num++.
". ".$_ - > {
   path
}.
"\n"
for @pythons;

my $sel = prompt("Use which?", '1');
$sel = $pythons[$sel - 1]
if $sel = ~/^\d+$/;
$sel = {
   path => $sel
}
unless ref $sel eq 'HASH';

print "Using $sel->{path}\n";

Solution: in Makefile.PL change $p value to "/python3" as shown below and it'll choose the right python version. Note: to make this changes you need to install perl packages by this method click here

# === === === === === === === === === === === === === === === === === === === === === === === === === =
   # What python are we going to
try ?
# === === === === === === === === === === === === === === === === === === === === === === === === === =
   my @pythons;
my $sep = $ ^ O eq 'MSWin32' ? ";" : ":";
for $p(split / $sep / , $ENV {
   PATH
}) {
   $p = ~s / ^ ~/$ENV{HOME}/;
   $p. = "/python3";
   push @pythons, {
      path => $p
   }
   if -f $p && -x $p;
}

Suggestion : 2

The Inline::Python module allows you to put Python source code directly "inline" in a Perl script or module. It sets up an in-process Python interpreter, runs your code, and then examines Python's symbol table for things to bind to Perl. The process of interrogating the Python interpreter for globals only occurs the first time you run your Python code. The namespace is cached, and subsequent calls use the cached version.,Inline::Python provides a full suite of exportable functions you can use to manipulate Python objects and functions "directly".,This document describes Inline::Python, the Perl package which gives you access to a Python interpreter. For lack of a better place to keep it, it also gives you instructions on how to use perlmodule, the Python package which gives you access to the Perl interpreter.,Whenever Inline::Python needs to return an instance of a class to Perl, it generates an instance of Inline::Python::Object, the base class for all Inline::Python objects. This base class knows how to do all the things you need: calling methods, in this case.

Example:

   use Inline Python => << 'END';

   import mymodule

   class A:
      class B: pass

   END
cpanm Inline::Python
perl - MCPAN - e shell
install Inline::Python

Suggestion : 3

This module provides regular expression matching operations similar to those found in Perl.,Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods, described below.,The text categories are specified with regular expressions. The technique is to combine those into a single master regular expression and to loop over successive matches:,Raw string notation (r"text") keeps regular expressions sane. Without it, every backslash ('\') in a regular expression would have to be prefixed with another one to escape it. For example, the two following lines of code are functionally identical:

>>>
import re
   >>>
   m = re.search('(?<=abc)def', 'abcdef') >>>
   m.group(0)
'def'
>>> m = re.search(r '(?<=-)\w+', 'spam-egg') >>>
   m.group(0)
'egg'
\
a\ b\ f\ n\ N\ r\ t\ u\ U\ v\ x\\
a = re.compile(r ""
      "\d +  # the integral part\.# the decimal point\ d * # some fractional digits ""
      ", re.X)
      b = re.compile(r "\d+\.\d*")
prog = re.compile(pattern)
result = prog.match(string)
result = re.match(pattern, string)

Suggestion : 4

This is the newest method of specifying your source code. It makes use of the Perl module "Inline::Files" written by Damian Conway. The basic style and meaning are the same as for the "DATA" keyword, but there are a few syntactic and semantic twists.,Finally, Inline supports several programming languages (not just C and C++). As of this writing, Inline has support for C, C++, Java, Python, Ruby, Tcl, Assembler, Basic, Guile, Befunge, Octave, Awk, BC, TT (Template Toolkit), WebChat and even PERL. New Inline Language Support Modules (ILSMs) are regularly being added. See Inline-API for details on how to create your own ILSM.,For information on writing your own Inline Language Support Module, see Inline-API.,If you are writing a module, you can also use the DATA section for POD and AutoLoader subroutines. Just be sure to put them before the first Inline marker. If you install the helper module "Inline::Filters", you can even use POD inside your Inline code. You just have to specify a filter to strip it out.

    use Inline C;
    print "9 + 16 = ", add(9, 16), "\n";
    print "9 - 16 = ", subtract(9, 16), "\n";
    __END__
    __C__
    int add(int x, int y) {
       return x + y;
    }
    int subtract(int x, int y) {
       return x - y;
    }

    use Inline X => "X source code";
2._
    use Inline Java => 'DATA';
    # Perl code goes here...
       __DATA__
    __Java__
    /* Java code goes here ... */
3._
    use Inline::Files;
    use Inline Java => 'file';
    # Perl code goes here...
       __JAVA__
    /* Java code goes here ... */
    use Inline Java => 'DATA';
    # Perl code goes here...
       __DATA__
    __Java__
    /* Java code goes here ... */
1._
    use Inline::Files;
    use Inline Java => 'file';
    # Perl code goes here...
       __JAVA__
    /* Java code goes here ... */

    use Inline C => 'below';
1._
    use Inline Java => << 'END';
    /* Java code goes here ... */
    END
    # Perl code goes here...

    my $code;
    BEGIN {
        $code = <<END;
    /* Java code goes here ... */
    END
    }
    use Inline Java => $code;
    # Perl code goes here ...
    

    my $code = <<END; /* Java code goes here ... */ END Inline->bind(Java => $code);