5

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?

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
maolingzhi
  • 681
  • 3
  • 8
  • 16

2 Answers2

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