有没有一种方法可以创建同时运行Python和Perl脚本的可执行文件? [英] Is there a way to create an executable that runs both Python and Perl script?

查看:144
本文介绍了有没有一种方法可以创建同时运行Python和Perl脚本的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Python程序,该程序也从内部运行Perl脚本.有没有一种方法可以创建可执行文件,而我的程序用户不必安装Perl但拥有Python?

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?

推荐答案

以下是如何使用 pp 生成可执行文件(不依赖于已安装perl可执行文件).

Here is an example of how you can use pp to build an executable (that does not depend on the perl executable being installed).

我在Ubuntu 20.04上将perlbrewperl版本5.30一起使用.

I am using perlbrew with perl version 5.30 on Ubuntu 20.04.

  • 首先安装pp:

cpanm PAR::Packer

  • 创建测试Perl脚本hello.pl(您可能需要先安装Path::Tiny):

  • 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
    

  • 通过擦除PATH,测试Perl脚本是否独立于perl可执行文件:

  • Test that the Perl script is independent of the perl executable, by erasing PATH:

    $ PATH= ./hello
    Hello world! CWD = /home/hakon/pp
    

  • 创建测试Python脚本t.py:

    import os
    os.system("./hello")
    

  • 运行Python脚本:

  • Run the Python script:

    $ python3 t.py
    Hello world! CWD = /home/hakon/pp
    

  • 我还使用Docker容器对此进行了测试,在该容器中,我将编译后的hello可执行文件传输到该容器,然后从该容器中运行hello.

    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.

    如果将此可执行文件传输到核心库版本(例如glibc)与构建可执行文件的计算机上使用的版本不同的计算机上,则该可执行文件可能无法在目标计算机上运行.请参阅这篇文章,以了解Python中的类似问题以及对该问题的进一步讨论.

    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.

    这篇关于有没有一种方法可以创建同时运行Python和Perl脚本的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆