【问题标题】:Export python script with dependencies to other Operating System将具有依赖关系的 python 脚本导出到其他操作系统
【发布时间】:2019-07-24 11:32:21
【问题描述】:

我想将以下代码从具有 python 2.7 的 MAC 导出到具有以下依赖项 (pynput) 的 Windows,该依赖项是从 pip 导入的。 我希望这个人能够在他们的终端中运行该文件而无需安装 pynput。 我尝试将文件转换为可执行文件,但它甚至无法在我的机器上运行。

代码如下:

import thread
import random
import time
from pynput.mouse import Listener, Controller, Button

mouse = Controller()
trigger = False

def on_click(x, y, button, pressed):
    global trigger
    if str(button) == "Button.middle" and pressed:
        trigger = True
        print "Middle button has been pressed"

    if str(button) == "Button.middle" and pressed == False:
        print "Middle button has been unpressed"
        trigger = False

def loop_thread(threadName, delay):
    while True:
        time.sleep(delay)
        if trigger == True:
            sleep_time = random.uniform(0.02, 0.12)x
            time.sleep(sleep_time)
            mouse.click(Button.left, 1)

def listener_thread(threadName, delay):
    with Listener(on_click = on_click) as listener:
        listener.join()

try:
   thread.start_new_thread( loop_thread, ("Thread-1", 0.025 ) )
   thread.start_new_thread( listener_thread, ("Thread-2", 0.25, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass

您知道是否有任何方法可以使 python 脚本跨平台并在所述脚本中包含依赖项?

【问题讨论】:

标签: python python-2.7 cross-platform pynput


【解决方案1】:

可执行文件需要在相同的操作系统上运行,所以没有冻结、Cython 或 nuitka。你可以试试pex,我认为它可以跨操作系统工作,你必须发送你的程序和 pex 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-03
    • 2016-04-11
    • 1970-01-01
    • 2013-11-23
    • 2016-07-31
    • 2014-07-04
    • 1970-01-01
    • 2017-03-09
    相关资源
    最近更新 更多