I'm building a Python program that also runs a Perl script from within. Is there a way to create an executable where the user of my program doesn't have to install Perl but has Python?
1 Answer
Here is an example of how you can use pp to build an executable (that does not depend on the perl executable being installed).
I am using perlbrew with perl version 5.30 on Ubuntu 20.04.
First install
pp:cpanm PAR::PackerCreate a test Perl script
hello.pl(you may need to installPath::Tinyfirst):use feature qw(say); use strict; use warnings; use Path::Tiny; # <-- NOTE: non-core module used say "Hello world! CWD = ", Path::Tiny->cwd;Pack it into an executable:
pp -o hello hello.plTest that the Perl script is independent of the
perlexecutable, by erasingPATH:$ PATH= ./hello Hello world! CWD = /home/hakon/ppCreate a test Python script,
t.py:import os os.system("./hello")Run the Python script:
$ python3 t.py Hello world! CWD = /home/hakon/pp
I also tested this with a Docker container where I transferred the compiled hello executable to the container and then ran hello from within the container.
Note:
If you transfer this executable to a machine with a different version of the core libraries (like glibc) than those used on the machine where the executable was built, the executable might fail to run on the target machine. See this post for similar issue in Python and further discussion of this problem.
perlinstalled