简体   繁体   中英

Is it safe to remove all python *.pyc files to force usage of new code?

TL;DR

  • Is it safe to pick all *.pyc (that has a matching *.py file) files and remove them to force usage of new code?
  • Is there a way to locate and re-compile all .py files found on disc while overwriting existing .pyc files?

I have an issue with a custom python package that got updated .

After the update (replaced old .py files with new .py files) iv'e noticed that when importing the package - old compiled code (stored as *.pyc files) got referenced instead of the newer code (lying in the .py files).

When i update a package i need to "flush the cache" (removing all of these pyc files hopefully they will get lazy initialized on first use) . As a hack i thought about removing all files found on disc matching *.pyc suffix (that has a matching *.py file) and rebooting the machine

Alternatively, is there a way to locate and re-compile all .py files found on disc while overwriting existing .pyc files?

Yes, it's safe. Use pyclean command

Usage: pyclean [-p PACKAGE] [DIR_OR_FILE]

pyclean .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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