Changing the directory where .pyc files are create

2019-01-23 11:15发布

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 to be implemented in the default interpreter (I'm working with Python 3).

Did I miss something ?

4条回答
够拽才男人
2楼-- · 2019-01-23 11:44

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.

查看更多
Bombasti
3楼-- · 2019-01-23 11:55

This might be useful for some: Miscellaneous options

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

New in version 2.6.
查看更多
放荡不羁爱自由
4楼-- · 2019-01-23 11:56

No, you didn't miss anything.

The .pyc files are always created at the location of the `.py file.

There are some really old patches around to disable the .pyc files completely though. But... why do you need to?

查看更多
欢心
5楼-- · 2019-01-23 12:01

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.

查看更多
登录 后发表回答