Changing the directory where .pyc files are created

后端 未结 4 1960
天涯浪人
天涯浪人 2020-12-08 19:05

Is there a way to change the directory where .pyc file are created by the Python interpreter? I saw two PEPs about that subject (0304 and 3147), but none seems

相关标签:
4条回答
  • 2020-12-08 19:36

    This might be useful for some: Miscellaneous options, especially -B option:

    If given, Python won’t try to write .pyc files on the import of source modules. See also PYTHONDONTWRITEBYTECODE.

    0 讨论(0)
  • 2020-12-08 19:40

    There's no way to change where the .pyc files go. Python 3.2 implements the __pycache__ scheme whereby all the .pyc files go into a directory named __pycache__. Python 3.2 alpha 1 is available now if you really need to keep your directories clean.

    Until 3.2 is released, configure as many tools as you can to ignore the .pyc files.

    0 讨论(0)
  • 2020-12-08 19:42

    Python files are NOT always stored in the same directory and will get directed to pycache if you use pycache. Any answers on being able to have custom locations and names, because importing the module is rather temperamental and doesn't always work. You will be able see what I mean at github.com/LolexInc/Lolex-Tools/tree/Beta and view JTToolsInstaller.py. There is a lot of mess in it.

    0 讨论(0)
  • 2020-12-08 19:43

    Yes, starting from Python 3.8 you can control this behavior. The original discussion starts from pep 304 in 2003.

    While this original PEP was withdrawn, a variant of this feature was eventually implemented for Python 3.8 in https://bugs.python.org/issue33499

    In the result, you can control using PYTHONPYCACHEPREFIX=path, -X pycache_prefix=path and sys.pycache_prefix.

    0 讨论(0)
提交回复
热议问题