0

How can I direct the .pyc files that are created to a different directory when the script is run? I'm running python 2.7.3 if it matters. They just clutter up my files when I run my .py files.

Vladimir Putin
  • 661
  • 1
  • 8
  • 18

1 Answers1

1

You cannot. .pyc files can only be written to the same location as the source file.

Python 3.2 moved to a __pycache__ subdirectory instead. Neither option is configurable.

At best you can disable bytecode files being written by either removing write access to the directory, setting the -B command line option when you run Python, or setting the PYTHONDONTWRITEBYTECODE environment variable.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343