我受到this article的启发,因为我考虑了混淆并降低了我的python应用程序对嵌入式设备的存储要求。我从命令行编译,然后删除所有* .py文件。
我的应用有很多模块(带有__init__.py
个文件的子目录),而且我只是删除了所有.py
源文件。如果我删除所有py源文件,我会收到导入错误。我试验过只剥离不是__init__.py
文件的.py源文件,但仍然会导致导入错误。 pycache目录还包含* .pyc(解释器生成的)和* .pyo(编译生成的)文件。 我只需要一种类型吗?
我在使用和不使用遗留-b
选项的情况下测试了compileall,但仍然可以获得相同的导入错误,该文件可以理解为不再存在。
from mypackage.mypyfile import my_main
是否有更多标准程序用于创建仅限pyo的分发?
# Clean potentially pre-existing cache
find mydir -type f -name "*.py[co]" -delete
find mydir -type d -name "__pycache__" -exec rm -r "{}" +
sync
# Byte-compile, ignoring .git subdirectories
python3 -m compileall -b -f -x r'[/\\][.]git' mydir
# Remove all source files
find mydir -type f -name "*.py" -delete
相关:Is there a way to combine a python project codebase that spans across different files into one file?
答案 0 :(得分:1)
似乎必须使用与用于字节编译的解释器和解释器标志相同的解释器和解释器标志来调用仅限pyo的分发:
SELECT * FROM GROUP WHERE find_in_set('17',grp_member);