简体   繁体   English

在开发过程中是否可以阻止Django创建.pyc文件?

[英]Is it possible to stop Django from creating .pyc files, whilst in development?

Is it possible to stop Django from creating the .pyc files? 是否有可能阻止Django创建.pyc文件? I know it's Python that creates them when modules are imported, but is there some way of turning them off? 我知道它是Python在导入模块时创建它们,但有没有办法将它们关闭?

Totally understand why they're created, etc, and will want them when I go live, but currently they just clutter up the directory and it bothers me - so please, no "you shouldn't want to turn them off". 完全理解为什么他们被创造等等,并且在我上线时会想要它们,但是目前他们只是把目录弄得乱七八糟,这让我感到困扰 - 所以请不要“你不应该把它们关掉”。 I also know how I could stop them appearing, etc, etc. I really just want to know how I can stop them being created. 我也知道如何阻止它们出现,等等。我真的只想知道如何阻止它们的创建。

Oh and I'm on Linux, of course. 哦,我当然在Linux上。

Thanks. 谢谢。

You can use this, where applicable: 如果适用,您可以使用此方法:

import sys

sys.dont_write_bytecode = True

You can try setting the PYTHONDONTWRITEBYTECODE environment variable: 您可以尝试设置PYTHONDONTWRITEBYTECODE环境变量:

PYTHONDONTWRITEBYTECODE PYTHONDONTWRITEBYTECODE

If this is set, Python won't try to write .pyc or .pyo files on the import of source modules. 如果设置了此项,Python将不会尝试在导入源模块时编写.pyc或.pyo文件。

New in version 2.6. 2.6版中的新功能。

Very late reply but I got here after Googling. 回复很晚,但谷歌搜索后我来到了这里。 You can try this: 你可以试试这个:

python -B manage.py [any other commands/options]

For example: 例如:

python -B manage.py sql yourapp

However, this doesn't work for some reason: 但是,由于某些原因,这不起作用:

python -B manage.py runserver 0.0.0.0:5000

编辑您的调度程序,因此hashbang读取:

#!/usr/bin/env python -B

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM