简体   繁体   English

阻止python生成pyc文件

[英]Stop python from generating pyc files

When I change my Python code, I often need to delete the associated pyc file, or Python will not regenerate it and will run the old code. 当我更改Python代码时,经常需要删除关联的pyc文件,否则Python将不会重新生成该文件并运行旧代码。 Is there a way to tell Python not to generated pyc files? 有没有办法告诉Python不要生成pyc文件?

When you import a file, Python will first look at the corresponding .py file, and if it's newer than the .pyc file, it'll be recompiled. 导入文件时,Python首先会查看相应的.py文件,如果该文件比.pyc文件新,则会对其进行重新编译。

I'd advise you to check that your system (and its clock) is acting sanely, so the .py files you modify get a new modified timestamp. 我建议您检查系统(及其时钟)是否运行正常,以便您修改的.py文件获得新的修改后的时间戳。

See the docs: http://docs.python.org/tutorial/modules.html#compiled-python-files 请参阅文档: http : //docs.python.org/tutorial/modules.html#compiled-python-files

Edit the .bashrc file and add the following lines to the very end of the file: 编辑.bashrc文件,并将以下行添加到文件的末尾:

PYTHONDONTWRITEBYTECODE=True
export PYTHONDONTWRITEBYTECODE

Restart your terminal or do the following: 重新启动终端或执行以下操作:

$ source ~/.bashrc

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

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