phs
phs

Reputation: 563

Can I choose where python's cached *.pyc files are created and stored?

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.

Upvotes: 1

Views: 2171

Answers (1)

Ethan Furman
Ethan Furman

Reputation: 69110

Update As of 3.8 it is now possible: you can control the base location by using PYTHONPYCACHEPREFIX=path, -X pycache_prefix=path, or sys.pycache_prefix.


Answer prior to 3.8:

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.

Upvotes: 2

Related Questions