python - 将具有依赖关系的 python 脚本导出到其他操作系统
问题描述
我想将以下代码从带有 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 脚本跨平台并在所述脚本中包含依赖项?
解决方案
可执行文件需要在相同的操作系统上运行才能工作,所以没有冻结、Cython 或 nuitka。您可以尝试pex,我认为它适用于整个操作系统,您将不得不发送您的程序和 pex 文件。
推荐阅读
- python-3.x - 如何将最新 (2020) Django 安装到 AWS EC2 Linux 2 实例并使用 Apache Hello World 服务
- mysql - 当我想在idea上运行我的j2ee+maven+spring-boot+mysql项目时,出现错误
- r - 将日期格式更改为 r 可以识别的格式
- c - 我在 CodeChef 中得到了错误的答案,我不知道为什么。我应该怎样做才能让它正确?这是一个例子
- flask - 将 gunicorn 与 joblib 并行使用时模型挂起
- sql - MS SQL 服务重启将删除 tempdb 中的用户设置
- r - 根据行号的散点图的颜色点
- c# - 远程拒绝主 -> 主(预接收挂钩被拒绝)错误:未能将一些参考推送到
- sql-server - 如何将 IP 分配给 WSL2 和/或 Docker 容器,以便可以从本地网络访问它
- javascript - JS:setInterval 运行就好像设置了多个间隔