使python脚本可双击

时间:2019-05-24 21:53:22

标签: python python-3.x

我有一个子程序,Popen是另一个子程序。 1)如何在Mac上使其双击? 我尝试了很多类似pyinstaller,platypus等的事情...

这是我的代码

import subprocess
import pyautogui
import sys
import timeit
import time



def get_var_value(filename="varstore.dat"):
    with open(filename, "a+") as f:
        f.seek(0)
        val = int(f.read() or 0) + 1
        f.seek(0)
        f.truncate()
        f.write(str(val))
        return val

your_counter = get_var_value()

p = subprocess.Popen([sys.executable, 'questions.py'],
    stdin=subprocess.PIPE)
p.stdin.write(b'N\nG\n0\na\n')
p.stdin.flush()
time.sleep(15)
p.stdin.write(b'\n')
p.stdin.flush()
p.stdin.write(f'GlobalAndroid{your_counter}\n'.encode())
p.stdin.flush()
p.stdin.write(b'omega\n')

2)我尝试了一些代码来插入Bot运行的时间,但是没有成功。 该脚本的基本作用是,打开我的“ questions.py”脚本,该脚本会在打开验证码之前询问4个问题,在完成验证码后,它会再问2个问题,然后才开始从0计数到“直到我停下来”(不要问我为什么哈哈哈,我有我的目标)。 我想要的是添加从开始计数到从开始计数到停止为止所花费的时间。 我用time.time()尝试了类似变量的其他操作,但是它给了我机器人一直运行直到验证码打开的时间,就像您在这里看到的

enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:0)

尝试添加shebang行。这必须是文件的第一行。

#!/usr/bin/env python

您可以使用您喜欢的任何Python解释器。您可以使用where找到命令的路径,例如

$ where python

然后您可以在shebang中使用绝对路径。这甚至适用于virtualenvs。

还必须设置可执行标志。使用$ chmod +x myscript.py来执行您希望执行的脚本。

如果您已经将.py扩展名与其他东西相关联,请尝试在macOS上将文件从.py更改为.command

如果您具有python.org的标准Python发行版,则还应该具有Python启动器。您可以将其与.py扩展名而不是IDLE关联。

您也可以尝试制作zipapp。然后,您将使用.pyz扩展名。