为没有 python 的用户创建一个 python exe - 可以处理服务器 CGI
create a python exe for users without python - that can handle server CGI
我编写了一个简单的 python 本地主机服务器,其中包含一个 python CGI 脚本。 CGI returns html 基于用户搜索。
我想构建一个编译版本,为用户创建本地主机并让他们运行 python CGI 脚本(无需安装python)。
我已经使用 pyinstaller 创建了服务器程序的 exe。然而,当 CGI 被调用时,它仍然试图 运行 未编译 python(用户的机器不会有)。
关于如何在不安装的情况下使 CGI 可供用户使用的想法 python?
我能够通过以下步骤让它工作:
- 使用 flask 而不是简单的 HTML 服务器 (CGIHTTPRequestHandler)。这对于提供静态文件来说是一个巨大的矫枉过正,但它确实有效。它需要最少的重构,因为 Flask 可以使用类似于 CGI 的方式获取信息:request.args.get
- 使用pyinstaller编译。这起初不起作用,但会生成一个 [your app].spec 文件。
篡改规范文件以根据此页面上的说明包含其他数据:https://www.quora.com/Can-I-convert-a-Flask-application-into-an-executable-file-that-runs-on-Windows-like-an-exe-file(这里确实有些巫术,但它有效!)
在 a.datas 调用中添加了我需要的其他目录(搜索索引)。
使用修改后的规范文件而不是 .py 文件重新运行 pyinstaller。
第3步添加的代码(是quora中的图片link)
hiddenimports=['email','email.message',
'email.mime.message', 'email.mime.image',
'email.mime.text', 'email.mime.multipart',
'email.mime.audio', 'email.mime.multipart',
],
def extra_datas(mydir):
def rec_glob(p,files):
import os
import glob
for d in glob.glob(p):
if os.path.isfile(d):
files.append(d)
rec_glob("%s/*" % d, files)
files = []
rec_glob("%s/*" % d, files)
extra_datas = []
for f in files:
extra_datas.append((f, f, 'DATA'))
return extra_datas
#include our data directories
a.datas += extra_datas("static")
a.datas += extra_datas("templates")
我编写了一个简单的 python 本地主机服务器,其中包含一个 python CGI 脚本。 CGI returns html 基于用户搜索。
我想构建一个编译版本,为用户创建本地主机并让他们运行 python CGI 脚本(无需安装python)。
我已经使用 pyinstaller 创建了服务器程序的 exe。然而,当 CGI 被调用时,它仍然试图 运行 未编译 python(用户的机器不会有)。
关于如何在不安装的情况下使 CGI 可供用户使用的想法 python?
我能够通过以下步骤让它工作:
- 使用 flask 而不是简单的 HTML 服务器 (CGIHTTPRequestHandler)。这对于提供静态文件来说是一个巨大的矫枉过正,但它确实有效。它需要最少的重构,因为 Flask 可以使用类似于 CGI 的方式获取信息:request.args.get
- 使用pyinstaller编译。这起初不起作用,但会生成一个 [your app].spec 文件。
篡改规范文件以根据此页面上的说明包含其他数据:https://www.quora.com/Can-I-convert-a-Flask-application-into-an-executable-file-that-runs-on-Windows-like-an-exe-file(这里确实有些巫术,但它有效!)
在 a.datas 调用中添加了我需要的其他目录(搜索索引)。
使用修改后的规范文件而不是 .py 文件重新运行 pyinstaller。
第3步添加的代码(是quora中的图片link)
hiddenimports=['email','email.message',
'email.mime.message', 'email.mime.image',
'email.mime.text', 'email.mime.multipart',
'email.mime.audio', 'email.mime.multipart',
],
def extra_datas(mydir):
def rec_glob(p,files):
import os
import glob
for d in glob.glob(p):
if os.path.isfile(d):
files.append(d)
rec_glob("%s/*" % d, files)
files = []
rec_glob("%s/*" % d, files)
extra_datas = []
for f in files:
extra_datas.append((f, f, 'DATA'))
return extra_datas
#include our data directories
a.datas += extra_datas("static")
a.datas += extra_datas("templates")