Felipe Lavratti
Felipe Lavratti

Reputation: 2967

Python is not saving .pyc files in filesystem

I have a python application running in an embedded Linux system. I have realized that the python interpreter is not saving the compiled .pyc files in the filesystem for the imported modules by default.

How can I enable the interpreter to save it ? File system permission are right.

Upvotes: 0

Views: 642

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295373

There are a number of places where this enabled-by-default behavior could be turned off.

  • PYTHONDONTWRITEBYTECODE could be set in the environment
  • sys.dont_write_bytecode could be set through an out-of-band mechanism (ie. site-local initialization files, or a patched interpreter build).
  • File permissions could fail to permit it. This need not be obvious! Anything from filesystem mount flags to SELinux tags could have this result. I'd suggest using strace or a similar tool (as available for your platform) to determine whether any attempts to create these files exist.

On an embedded system, it makes much more sense to make this an explicit step rather than runtime behavior: This ensures that performance is consistent (rather than having some runs take longer than others to execute). Use py_compile or compileall to explicitly run ahead-of-time.

Upvotes: 2

Related Questions