Domanda

I have looked in PyCharms FILE-SETTINGS-FILE STRUCTURE and I can see only a small directory which houses all my .py files. The indexer appears however to dance around a large proportion of the file system and is now taking sometimes 15 minutes at a time to complete.

I was wonder firstly what purpose has indexing, and secondly how can I limit the PyCharms indexing list.

È stato utile?

Soluzione

Indexing considers all the directories in the PYTHONPATH. You can have an idea of what these are printing sys.path:

>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

As you can see there are a few directories in the path by default. These depend on the OS and python version.

In particular there are system-wide dist-packages (previously called site-packages) directories (/usr/lib/python2.7/dist-packages) in this example. That's where most packages are installed.

PyCharm will look into these directories, parse all the contents of the packages/modules it finds in order to obtain information about their structure and everything they define. This allows to implement autocompletion for them when you write code inside the editor, or things like jumping to the declaration/usage of something.

You can find a list of these directories in the projects settings under Python Interpreters. On the bottom there is a tabbed view that has a Paths tab which lists these directories.

As far as I know it's not possible to avoid indexing (at least searching indexing in the settings doesn't turn out anything useful from this point of view). However you could use fresh virtual environments for your projects which wouldn't require a system-wide scan. Also using an environment that contains only the dependencies that your project needs can help you in understanding its structure and it avoids errors such as wrongly uninstall a package that was required.

In the Python Interpreters page, at the very bottom, there's a create new VirtualEnv that allows you to create a virtual environment from inside PyCharm.


Note that not doing indexing means that all the features of PyCharm that relates to looking up sources (e.g. autocompletion, jump to declaration, show usages etc) will not work for the not-indexed packages/modules.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top