【发布时间】:2022-01-28 00:28:10
【问题描述】:
我有一个 python 文件,我想打包为 MacOS 11.6 的可执行文件。
python 文件(称为 Service.py)依赖于另一个 json 文件,并且在使用 python 运行时运行良好。我的文件使用 argparse,因为参数可能因需要而异。
如何用python调用文件的例子:
python3 Service.py -v Zephyr_Scale_Cloud https://myurl.cloud/ philippa@email.com password1 group3
当文件是可执行文件时,它的运行方式完全相同:
./Service.py -v Zephyr_Scale_Cloud https://myurl.cloud/ philippa@email.com password1 group3
我可以使用 PyInstaller 打包文件并运行可执行文件。
用于打包文件的命令:
pyinstaller --paths=/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ Service.py
但是,当我到达需要多处理的地步时,参数就会丢失。我的第二个参数(这里记为 https://myurl.cloud)是我需要的 URL。
我看到的错误是:
[MAIN] Starting new process RUNID9157
url before constructing the client recognised as pipe_handle=15
usage: Service [-h] test_management_tool url
Service: error: the following arguments are required: url
Traceback (most recent call last):
File "urllib3/connection.py", line 174, in _new_conn
File "urllib3/util/connection.py", line 72, in create_connection
File "socket.py", line 954, in getaddrinfo
我已经完成了一些日志记录,并且确实可以正确读取 url。但是一旦进程启动并获取它需要的内容,url 就会更改为“pipe_handle=x”,在上面的代码中它是 pipe_handle=15。 我需要 url 来检索身份验证令牌,但它只是停止被读取为正确的值并更改为此 pipe_handle 值。我不知道为什么。
还有其他人看过吗?!
我正在使用 Python 3.9、PyInstaller 4.4 和 ArgParse。 我也加了
if __name__ == "__main__":
if sys.platform.startswith('win'):
# On Windows - multiprocessing is different to Unix and Mac.
multiprocessing.freeze_support()
到我的 if name = "main" 部分,因为我在其他帖子上看到了这个,但它没有帮助。
有人可以帮忙吗?
【问题讨论】:
标签: python multithreading multiprocessing pyinstaller argparse