操作流程:
使用pyinstaller打包python运行环境和依赖库到一个文件,然后通过 exec(open(file, encoding="utf-8").read()) 执行自定义py脚本。
main.py
#encoding:utf-8 import os import sys import re import json import base64 import zlib import requests import flask def main(): if len(sys.argv)==1: print("usage: %s run.py"%sys.argv[0]) file = "run.py" else: file = sys.argv[1] exec(open(file, encoding="utf-8").read()) if "__main__"==__name__: main()
run.py
from flask import Flask app = Flask(__name__) @app.route("/", methods = ["GET"]) def index(): return "Hello World." app.run("0.0.0.0", 80)
打包命令:
pyinstaller -F main.py --noupx
my github:
https://github.com/wstone0011/pyone