我试图编译 python 源文件但没有成功。根据documentation ,compileall.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/