Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 222
Davita Avatar asked Apr 01 '26 12:04

Davita


1 Answers

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.

like image 64
falsetru Avatar answered Apr 03 '26 06:04

falsetru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!