嘿,我只是想到了一件事:我只需要 stdlib 中所有模块的列表,然后我会自动生成一个“手动”导入每个模块的 Python 脚本,如下所示:
import re
import math
import time
# ...
Run Code Online (Sandbox Code Playgroud)
然后将其包含在我的程序中。
所以我现在需要的是 stdlib 中所有模块/包的易于格式化的列表。现在我该如何得到它?
更新:
我得到的列表是这样的:我在虚拟机上安装了Python 2.6,然后在IDLE中运行:
import pkgutil
stuff = [thing[1] for thing in pkgutil.iter_modules()]
stuff.sort() # To make it easy to look through
print(stuff)
Run Code Online (Sandbox Code Playgroud)
然后将输出复制粘贴到我的 IDE 中,并编写一个小脚本来编写:
if False:
import re
import email
import time
# ...
Run Code Online (Sandbox Code Playgroud)
进入我在程序中导入的Python模块。
有用!py2exe 打包整个 stdlib。
更新:
我创建了一个包来执行此操作。我会在这里上传它,但由于我没有看到任何上传按钮,您可以将其从我的项目文件夹中获取:
http://github.com/cool-RR/PythonTurtle/tree/master
它位于 文件夹中src
,调用该包almostimportstdlib
并对其进行记录。