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. Is there a way to tell Python not to generated pyc
files?
Asked
Active
Viewed 4,619 times
5

Michael Mrozek
- 169,610
- 28
- 168
- 175

maolingzhi
- 681
- 3
- 8
- 16
-
3Python should automatically make new `.pyc` files whenever the source `.py` files have changed. Why do you think that is not happening? – Steven T. Snyder Feb 23 '12 at 06:49
-
4Also, I think this is an exact duplicate of http://stackoverflow.com/questions/154443/how-to-avoid-pyc-files – Steven T. Snyder Feb 23 '12 at 06:49
2 Answers
5
Edit the .bashrc
file and add the following lines to the very end of the file:
PYTHONDONTWRITEBYTECODE=True
export PYTHONDONTWRITEBYTECODE
Restart your terminal or do the following:
$ source ~/.bashrc

kenlukas
- 3,616
- 9
- 25
- 36

Gopinath Langote
- 311
- 4
- 10
3
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.
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.
See the docs: http://docs.python.org/tutorial/modules.html#compiled-python-files

AKX
- 152,115
- 15
- 115
- 172