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.
Asked
Active
Viewed 226 times
0
-
@SomeGuy: the answer for 2.7 is the same as for 3.0 and 3.1. – Martijn Pieters Jun 29 '14 at 23:56
1 Answers
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