便携式python应用程序可在远程系统上运行 [英] Portable python app to run on remote systems

查看:115
本文介绍了便携式python应用程序可在远程系统上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一个独立的便携式python应用程序,并在没有安装python解释器或版本不同的远程系统上运行.

目标是将python脚本打包为一个应用程序,将其传输到远程系统并作为独立的应用程序运行,而没有任何依赖关系.

在Python世界中,我们有这种方法吗?有人做过类似的事情吗?

解决方案

冻结是游戏的名称.

这是使用PyInstaller的示例.

示例脚本test.py:

 #!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce


my_list = list('1234567890')

my_list = list(map(lambda x: int(x), my_list))
my_sum = reduce(lambda x, y: x + y, my_list)

print("The sum of %s is %d" % (list(my_list), my_sum))
 

要从脚本创建二进制文件,请安装PyInstaller并在您的代码上运行它:

$ pyinstaller -F test.py

完成后,您应该在./dist中找到独立的二进制文件.当您运行它时,它的行为就像其他任何程序一样:

 $ ./dist/test
The sum of [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] is 45
 

有关更多信息,请在此处

I am in need to generate a standalone portable python application and run on remote systems where even python interpreter is not installed or version is different.

The aim will be to pack the python script as an app, transfer it to the remote systems and run it as a standalone app without any dependencies.

Do we have such a way in the Python world? Has anybody done a similar thing before?

解决方案

Freezing is the name of the game.

Here's an example using PyInstaller.

A sample script test.py:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce


my_list = list('1234567890')

my_list = list(map(lambda x: int(x), my_list))
my_sum = reduce(lambda x, y: x + y, my_list)

print("The sum of %s is %d" % (list(my_list), my_sum))

To create a binary from the script, install PyInstaller and run it on your code:

$ pyinstaller -F test.py

After it finishes, you should find the standalone binary in ./dist. When you run it, it behaves just like any other program:

$ ./dist/test
The sum of [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] is 45

For more information, take a look here

这篇关于便携式python应用程序可在远程系统上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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