0

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?

7
  • if you're calling a perl script from python, you have to have perl installed too. Commented Apr 28, 2020 at 17:51
  • @Snow oh man! okay. Thank you! Commented Apr 28, 2020 at 17:52
  • I did post a similar question but I didn't get any replies and instead got down votes so I deleted it. My apologizes. Commented Apr 28, 2020 at 18:17
  • 2
    See also pp for a way to create an executable of your Perl script that does not need to have perl installed Commented Apr 28, 2020 at 20:07
  • 1
    @HåkonHægland -- but if the code will be dependent on additional module the final result is not guaranteed. Commented Apr 28, 2020 at 20:58

1 Answer 1

1

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::Packer
    
  • Create a test Perl script hello.pl (you may need to install Path::Tiny first):

    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.pl
    
  • Test that the Perl script is independent of the perl executable, by erasing PATH:

    $ PATH= ./hello
    Hello world! CWD = /home/hakon/pp
    
  • Create 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.