python - 编译 *.py 文件

标签 python python-3.x

我试图编译 python 源文件但没有成功。根据documentationcompileall.compile_dir 函数有“ddir”参数,(我猜)它指定了 .pyc 文件的目标文件夹。我尝试用这个脚本编译它:

import compileall

compileall.compile_dir(".", force=1, ddir=".")

但它不起作用。我看到了终端的输出(编译、列表等),但没有生成 pyc 文件。任何人都可以帮助我了解 pyc 文件的存储位置以及如何更改该默认行为?

谢谢

最佳答案

检查 __pycache__ 目录。从 Python 3.2 开始,编译后的文件收集在 __pycache__ 目录中。

参见 PEP 3147: PYC Repository Directories - What’s New In Python 3.2 .

顺便说一句,ddir 不是目标目录。根据the documentation :

If ddir is given, it is prepended to the path to each file being compiled for use in compilation time tracebacks, and is also compiled in to the byte-code file, where it will be used in tracebacks and other messages in cases where the source file does not exist at the time the byte-code file is executed.

关于python - 编译 *.py 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26324540/

相关文章:

python - 尝试删除打印机时访问被拒绝

Python 3.5 字典比较

python - 实现 Jedi 可以理解的惰性属性

python - 在 Python 中递归镜像嵌套元组

python-3.x - Azure Python 函数中导入模块错误 (Linux)

python - 删除循环的新行?

python - 使用plotly保护数据隐私

python - 如何在 Python 中访问字典的内部字典项

python - numpy中两个 float 之间以对数间隔的数字

python - 在 numpy 数组中按最大值或最小值分组