0

This is a followup to the earlier What is __pycache__? question.

Is there a way to tell python-3.x to always put its __pycache__ directory (or the *.pyc files it contains) in some designated place. E.g. by setting some environment variable like PYCACHEDIR=${HOME}/bin/python-cache?

For the record, I am using Mac OS X.10.3 & python3 installed with brew.

Community
  • 1
  • 1
phs
  • 541
  • 3
  • 18
  • Why would you want such a thing anyway? If you just want to remove them, you can create a script that recursively deletes all those files/directories in your folder and subfolders. I am not seeing why you should need to put those files in another directory...please enlighten me! – nbro Jun 04 '15 at 20:12
  • 1
    Since you need to know, the name pycache sounds exactly like something really gross in our local slang. And I like the way many things in unix-like systems can be customized by the user. – phs Jun 05 '15 at 06:08
  • 1
    I was wondering the same thing. I have a case where the directories with the source files are not writable, and want to relocate the pycache so that all users can benefit from the cache without having write access to the actual python source file directories. – mattgately Aug 16 '16 at 17:20
  • 1
    Possible duplicate of [Changing the directory where .pyc files are created](http://stackoverflow.com/questions/3522079/changing-the-directory-where-pyc-files-are-created) – mattgately Aug 16 '16 at 17:22

1 Answers1

1

No, you cannot. The __pycache__ directory is where Python will look for pre-compiled files that match the requested .py file, and its location is not negotiable.

djromero
  • 19,551
  • 4
  • 71
  • 68
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237