0

I have Python 3.8 installed via Anaconda. I am running a Python script from the command line and I am getting the following error:

ImportError: bad magic number in 'myscript': b'B\r\r\n'

Following some research online, I came across a post where the author stated that the solution is to run the following lines to clear the cache folders:

find . -name \*.pyc -delete

Since I'm new to Python, I would like some help on the following:

(1) Where do I run that command?

As I mentioned above, I installed Python using Anaconda. So, do I just need to get into the following path in my command prompt (C:\Users\xxxx\Anaconda3) and run the codes from there?

(2) Is it safe to delete all the "pyc" folders?

user3115933
  • 4,303
  • 15
  • 54
  • 94

1 Answers1

0

The command needs to be run from a UNIX-ish command line - something like Cygwin or Git bash on Windows.

Using Cygwin, you should be able to run something along the lines of

cd /cygdrive/c/Users/xxx/Anaconda/Lib/site-packages # omit /cygdrive if using Git bash

I don't use Anaconda and I'm not sure what the exact file path is, so you should confirm it using Windows explorer. There may be a Python version somewhere in there.

Once you're in the proper site-packages directory, you can run

find . -name \*.pyc -delete

and you should be all set.

In response to your second question, yes, it is safe to delete .pyc files. Your imports will just take a little longer to run the next time you use them, as they'll be recreating their respective .pyc files from scratch.

See If Python is interpreted, what are .pyc files? (the second answer, specifically) for an explanation of what .pyc files are.

MattDMo
  • 100,794
  • 21
  • 241
  • 231