A. Innokentiev A. Innokentiev - 5 months ago 18
Python Question

Removed .py files, compiled .pyc files and git - how to?

I have removed some files (

a.py
and
b.py
) from project and committed my changes. My teammate pulled changes and program exited with errors.

After some research we have found problem:
Git removed
a.py
and
b.py
files, but compiled
.pyc
files remained and caused problems - program used old sources and get an errors.

.pyc
files ignored in
.gitignore
.

What is the best solution to solve such problem?

UPDATE: I know how to ignore files - question not about it. Question is how to avoid situations described above?

Answer

You will simply have to go through and delete the .pyc files. The python interpreter is such that the .pyc files are always used unless the .py files are newer (in which case it recompiles the .pyc file).

A good solution is to include a cleaning step in your workflow that removes all .pyc files before running the program:

find . -name "*.pyc" -delete
Comments