29

I changed my project code from python 2.7 to 3.x.

After these changes i get a message "cannot find declaration to go to" when hover over any method and press ctrl

I'm tryinig update pycharm from 2017.3 to 18.1, remove directory .idea but my issue still exist.

Do you have any idea how can i fix it?

halfelf
  • 9,737
  • 13
  • 54
  • 63
qchar90
  • 404
  • 1
  • 5
  • 11

6 Answers6

76

Right click on the folders where you believe relevant code is located ->Mark Directory as-> Sources Root

Note that the menu's wording "Sources Root" is misleading: the indexing process is not recursive. You need to mark all the relevant folders.

kakyo
  • 10,460
  • 14
  • 76
  • 140
mithunpaul
  • 3,268
  • 22
  • 19
  • This worked for me, mostly because the main project is PHP and i have a small python module, so i had to click on the python directory to mark it as root – Long M K Nguyễn May 07 '19 at 18:06
  • 2
    Note that for Django projects, you only have to mark the Django root directory as "Sources root" (the one that has `manage.py`) and it will automatically detect your project structure. – Eduard Luca Jul 09 '20 at 09:32
  • This worked for me – Onengiye Richard Nov 02 '21 at 17:28
  • I had to invalidate my cache and reindex the project for these changes to take effect: "File" -> "Invalidate Caches..." -> "Invalidate and Restart" – Akaisteph7 Aug 29 '23 at 14:56
8

I had same issue and invalidating cache or reinstalling the app didn't help. As it turned out the problem was next: for some reasons *.py files were registered as a text files, not python ones. After I changed it, code completion and other IDE features started to work again.

To change file type go Preferences -> Editor -> File types

Maksim Yushin
  • 96
  • 1
  • 3
7

What worked for me was right-click on the folder that has the manage.py > Mark Directory as > Source Root.

herickmota
  • 457
  • 6
  • 13
  • Please don't add _"thanks"_ as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Instead, [upvote answers](http://stackoverflow.com/help/privileges/vote-up) you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See [Why is voting important](http://stackoverflow.com/help/why-vote). – Yunnosch Jul 21 '20 at 08:49
  • 1
    This is really worked for me, now I able to navigate the source code. – Sameel Oct 06 '21 at 16:53
  • This is just a copy of the accepted answer – Akaisteph7 Aug 29 '23 at 14:52
1

I had a case where the method was implemented in a base class and Pycharm couldn't find it.

I solved it by importing the base class into the module I was having trouble with.

mp808
  • 21
  • 3
1

The solution for me: remember to add an interpreter to the project, it usually says in the bottom right corner if one is set up or not. Just an alternate solution than the others.

This happened after reinstalling PyCharm and not fully setting up the ide.

Axisnix
  • 2,822
  • 5
  • 19
  • 41
0

Go to settings. --> Plugins. Uninstall the unnecessary plugins. In my case I had 5 plugins. I disabled and uninstalled all plugins except Intellibot plugin. Others create unnecessary extensions.

Then, go to Settings. --> File Types --> Select Robot Featured Files. Add ".resource". Then Ok. Again, Add ".robot". Then Ok.

Apply and Ok settings. Wait for indexing or sny other other process on applying changes. Maybe after a minute restart your pycharm.

This worked for me.

(There is a star sign before .resource and .robot. Not sure why it didn't appear when i posted answer).