4

I am currently reading a book called "Test-Driven Development with Python" In chapter1, I have to use

git rm -r --cached superlists/__pycache__

to remove all the .pyc files, I got the error the same in the title. I have searched many similar problems in this forum, I still cannot figure it out how to solve it. Hope someone could help me. Many Thanks

user3084591
  • 91
  • 2
  • 7
  • Are you sure that you need to do this? Unless you actually added the `__pycache__` directory to git in the first place - and I can't see why you would - you wouldn't need to remove it. – Daniel Roseman Nov 10 '15 at 22:09
  • Yes, I did add the .pyc files to git using `git add .`, if you read that book, you will see the author tried to use the same code to remove the .pyc files. – user3084591 Nov 10 '15 at 23:14

2 Answers2

2

I got the same error while doing executing the same command:

Solution 1:
One of the stackoverflow answers mentions his usual buildout have the have .pyc in the .gitignore file - link to the answer I did that and then did the "$ git add ." command. It worked and the __pycache__ files were not added.

$echo "*.pyc" >> .gitignore

Solution 2:
I cleaned the staging area for the files to be commited and then executed the same command. It worked

$git reset
$git rm -r --chached superlists/__pycache__

screenshot for Solution 2 Hope it helps!

Community
  • 1
  • 1
0

Your error, Error fatal: pathspec did not match any files, means that the pathspec you specified (superlists/__pycache__) doesn't match any files that are being tracked by git.

In the previous steps had you added the __pycache__ files to git?

Are there any __pycache__ files in the superlists directory? Have you run the superlists code? Perhaps you have your python configured to not output .pyc cache files?

What is the output of ls -a superlists and ls -a superlists/__pycache__?

spazm
  • 4,399
  • 31
  • 30
  • Yes, I did add the __pycache__ files to git in the previous step by using `git add .` Actually, this is the output when I run `ls -a superlists` : __init__.py settings.py urls.py wsgi.py __init__.pyc settings.pyc urls.pyc wsgi.pyc. Also this is the code the author used in the book to remove the .pyc files. I have no idea where it went wrong – user3084591 Nov 10 '15 at 23:21