python - 字节编译后删除python源文件?

标签 python bytecode

我可以在字节编译后删除python源文件(*.py)吗?我知道这不提供安全性,并且 .pyc/o 文件可以很容易地进行逆向工程;我只想在一次发布中发布更少的文件。

# Clean the python cache
find ./mypythonstuffs -type f -name "*.py[co]" -delete
find ./mypythonstuffs -type d -name "__pycache__" -delete

# Remove test directories
find ./mypythonstuffs -name "test" -type d -exec rm -r "{}" \;

# Byte-compile, ignoring .git subdirectories
python3 -O -m compileall -f -x r'[/\\][.]git' ./mypythonstuffs

# Remove now-unnecessary??? python source files
find ./mypythonstuffs -type f -name "*.py" -delete

最佳答案

请不要这样做。

首先,python 字节码是一个未记录的实现细节。不能保证将字节码分发给其他人会真正起作用。

其次,它使调试变得困难。你知道回溯是如何显示源代码行的吗?这是从原始源文件中获取的。即使您根本不关心 FOSS,您仍然应该关心从用户那里获得有用的错误报告。

第三,实在没有必要。如果您想分发更少的文件,只需分发 python 源文件。字节码是一个实现细节。您一开始就不应该 checkin 或分发它。

关于python - 字节编译后删除python源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33488299/

相关文章:

Python:UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0 的字节 0x80:无效的起始字节

ruby - 编译或混淆的 Ruby

Python Selenium 错误元素在该点不可点击

python - python 中的嵌套范围

winkler 的 Python 性能改进请求

java - 如何在 asm 代码中正确使用 Instrumentation.retransformClasses()?

Python Argparse 向子解析器添加一个没有名称的参数

python - pytz 时区标签以调整模板中打印的日期

php - PHP APC 可以用来将源代码转换为字节码吗?

java - 汇编 : Stateful Transformation