Pycharm: "scanning files to index" is taking forever

45,104

Solution 1

Exclude the folders you do not want to index. You can do this by right-clicking the folder you want to exclude, then choose Mark Directory As > Excluded and PyCharm will not index those files.

Solution 2

In some cases, this is because Pycharm scans and indexes the PYTHONPATH. I figured out that some shared script I was running got changed by some nincompoop (may his severed head soon decorate our moat) and the /homes directory got into the PYTHONPATH.

How to get it out: Go to File->Settings->Project:[your project]->Project Interpreter

On the right hand side you'll see a cogwheel, click it, then select Show all...

In the next window, your environment will be selected. There are a few icons on the right hand side of this window, one of them is a directory tree. Click it.

You'll find a list of all interpreter paths. Remove the directory that is causing your problem, dance a little victory dance, and resume work.

Solution 3

Maybe there are some issues in project files? Try to remove .idea folder inside your project (but this will also purge all project settings).

Solution 4

In my experience it can be any of the following problems:

  • You added a new folder to your project which includes many files. Then follow the tip from sP_ and use Right click > Mark Directory As > Excluded
  • You added a zip file to your project. Then follow the tip from kusiroll and use Right click > Mark Directory As > Excluded. Or remove.
  • You just had this problem for the first time. Use File > Invalidate Cache and Restart
  • It happens on a specific project. If you're willing to give up all your project settings, delete the .idea folder of the project. The tip of Igor Pomaranskiy.
  • If you are working on linux you could check this answer in a similar question.
  • It keeps happening. If you're willing to give up all your settings, delete the ~\.PyCharm201X folder.

Solution 5

PyCharm will index every file unless told otherwise. The previous answers show you how to exclude a folder.

But if there are certain file types that you never need to index, such as log files, data files, compressed files, etc. (but for some reason happen to appear in your project), you can instruct PyCharm to ignore specific file extensions. Just append those file extensions to the list

Preferences > Editor > File Types > Ignore Files and Folders

Use a semicolon to separate the entries.

Note that this is a global Ignore list; there doesn't seem to be a way to exclude extensions by project.

One way to discover which file types may be causing indexing to bog down is to identify the largest files in your codebase.

Share:
45,104
sP_
Author by

sP_

Meh.

Updated on July 05, 2022

Comments

  • sP_
    sP_ almost 2 years

    I am using PyCharm Community Edition 5.0.1 It was working fine till yesterday. But it has been stuck at 'Scanning files to index' for a very long time now. Since yesterday.

    I have tried re-installing it, and also tried invalidating cache.

    I can make changes to programs and use it as a text editor but unable to run any file.

  • sP_
    sP_ over 8 years
    I had 7 directories open. I closed the one at random, it then finished scanning in like 3 minutes. Thanks.
  • fred271828
    fred271828 about 7 years
    This was happening for me for a virtualenv directory with only 5000 files.
  • Pramesh Bajracharya
    Pramesh Bajracharya over 5 years
    After reinstalling pycharm (multiple times), invalidating cache(more than multiple times) and cursing pretty much everybody on the day of christmas. .... 6 hours later, this solved the problem. Thanks a lot man.
  • Hack-R
    Hack-R about 5 years
    What's the context where you can do this? In my case I started a new project and it immediately began indexing the entire TB hdd. Where can you right-click and exclude the folders?
  • ivan866
    ivan866 over 4 years
    Mark directory as excluded actually works. Stopped indexing right away. Lubuntu 18.04 with PyCHarm 2019.3 Community.
  • Kasparov92
    Kasparov92 over 3 years
    Thanks! Excluding a folder with many images stopped indexing right away! :D