Davita
Davita

Reputation: 9114

Compiling *.py files

I'm trying to compile python source files without success. According to documentation, compileall.compile_dir function has "ddir" parameter, which (I guess) specifies the destination folder for .pyc files. I try to compile it with this script:

import compileall

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

but it doesn't work. I see output from terminal (compiling, listing etc.) but pyc files are not generated. Anyone can help me understand where pyc files are stored and how to change that default behavior?

Thanks

Upvotes: 3

Views: 1117

Answers (1)

falsetru
falsetru

Reputation: 368894

Check __pycache__ directories. Since Python 3.2, the compiled files are collected in __pycache__ directories.

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

BTW, ddir is not destination directory. According to 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.

Upvotes: 2

Related Questions