I have a server running a Python app. I'm updating the app's code manually via sftp.
Is it safe to remove the *.pyc
files that are automatically created in my app's dir?
Asked
Active
Viewed 8,228 times
4

Jossef Harush Kadouri
- 32,361
- 10
- 130
- 129
-
31. Yes. You don't have to reboot, if the .pyc is missing it will be automatically generated. Note that .pyc are automatically regenerated if its .py is newer. 2. [How can I manually generate a .pyc file from a .py file](http://stackoverflow.com/questions/5607283/how-can-i-manually-generate-a-pyc-file-from-a-py-file) – Vincent Savard Jun 27 '16 at 15:04
-
2compileall : http://stackoverflow.com/a/22779209/2142994 – Ani Menon Jun 27 '16 at 15:06
-
Possibly related to http://stackoverflow.com/questions/5629135/python-not-interpreting-changed-files-using-obsolete-pyc – André Laszlo Jun 27 '16 at 15:06
-
In my personal opinion is not needed, anyway you can use this to recompile all the python files on filesystem find / -iname '*.py' | xargs python -m py_compile – user2543740 Jun 27 '16 at 15:07
1 Answers
5
Yes, it's safe. Use pyclean
command
Usage: pyclean [-p PACKAGE] [DIR_OR_FILE]
pyclean .

Jossef Harush Kadouri
- 32,361
- 10
- 130
- 129
-
`Command 'pyclean' not found, but can be installed with: sudo apt install python2 ` – Qohelet Feb 15 '21 at 14:35