PyCharm code inspection not working

I recently upgraded to PyCharm Professional 2020.3.2 on Mac OS Catalina 10.15.7.  When I did that it disabled code inspection for the project I had open at the time I upgraded.  It is odd that it is only one project that code inspection seems to be disabled on.  I checked the preferences and almost all the settings under Preferences->Editor->Inspections for python are checked.  If I open another project the code inspection works.

One simple example of a code inspection that is not working is adding an import for a package that is not used.  Previously I would see PEP8 warnings as well is the line highlighted in some manner to indicate the import is unused.

Here is what I've tried to date that hasn't worked:

  • Exit out of pycharm completely and restart
  • Downgrade back to previous version (2020.3)
  • Recreated the project code inspection is not working in
  • Restore the settings to the default settings (File->Manage IDE Settings->Restore Default Settings)
1
22 comments

Hi, could you please provide screenshot demonstrating the issue, and a screenshot of your project structure. 

Also, is it possible to provide minimal sample of the affected project? (e.g., if you remove most of the code and leave only code necessary to reproduce the issue).

0

Hi, I had the same issue. I tried also different things on my project settings. In the end via File -> Invalidate Caches / Restart ... could solve this problem. Now the inspection works as expected. Maybe this could help you.

0

Thanks for the suggestion Steffi.  I tried the File -> Invalidate Caches / Restart but that did not resolve the problem for me.

0

Andrey,

Here is an example of a working file marking an import as unused

Here is an example where the import is not marked as unused

Here is an example of an unused variable properly marked as such

Here is an example where the unused variable is not marked

What exactly are you looking for as far as the project structure?  Not sure I can easily provide you the minimal sample as it is a rather large project.  I can see if I can make a copy and reduce it down to a few files that allow me to reproduce the problem.  Will let you know if I'm able to do that.

Keith

 

 

0

>What exactly are you looking for as far as the project structure?

Want to make sure the source dir is not excluded, not inside venv dir, e.t.c.

Is interpreter configured correctly, can you run the code?

Make sure that:

- Power save mode is not enabled in File menu

- Highlight level is set to all problems

Try disabling reader mode in **Preferences | Editor | Reader Mode**

0

I copied my project to another directory and then created a new pycharm project using the new directory.  When the new project was created all the code inspection worked as expected.  This seems to indicate there are some project related settings being saved somewhere. 

How would I go about deleting all pycharm related project files so I could in essence start over from scratch similar to copying the files to a new directory and creating a new project from there?

I deleted the .idea file in the root directory of my project and removed the project from recent projects but that did not clear things up.

0

Hi Andrey, Power save mode was not enabled and disabled reader mode.  Neither of those made a difference.  I couldn't locate the Highlight level setting you showed.  How do you navigate to that?

One thing I did try was selecting Navigate->Next Highlighted Error and that seemed to fix things.

Hope that may help figure out what may have triggered this problem.

0

Schomburg, Keith I've got exactly the same problem with only one of my projects, the one that I was working on when I updated Pycharm and restarted. I tried to invalidate caches and it didn't work. I tried all the ideas by Andrey Resler and it didn't solve the problem. I also removed the entire ".idea/ " directory in the project base and restored all settings to default and still it didn't solve it. supper strange and annoying.

0

Mrezzamoradi Please make sure the **Preferences | Editor | Reader Mode** is disabled, and if this doesn't help, I suggest to submit a bug report to https://youtrack.jetbrains.com/issues/py with Logs from **Help | Collect Logs and Diagnostic Data**

0

Andrey Resler Thanks for your suggestions. It is not in Reader Mode, and I cannot reproduce it to submit a bug report. Interestingly an exact copy of the project doesn't have this issue (copy via "cp -a"). More interestingly the issue appears again if you rename the copied directory back to the original directory name. I had another issue with the same project regarding font ligatures and copying solved that too. Here's a bug report for that one https://youtrack.jetbrains.com/issue/PY-46023

 
0

Invalidate caches didn't work for me, but I solved this problem by switching to a new Python Interpreter.

1
Avatar
Permanently deleted user

I have the same problem, started recently with the new version 2021.2
If I restart PyCharm inspections works perfect, but after a while of coding, inspections crash and stop working, sometimes to solve this I have to select other interpreter and than select back the olther one, I also tried to reinstall everything from scratch, PyCharm + venv and same problem.

1

Hello @Vali, 

it would be great to investigate this. Please submit a report at

https://youtrack.jetbrains.com/issues/PY , attach a couple of screenshots and

logs folder zipped from ***Help | Collect logs and Diagnostic Data*** . 

 

 

 

0

Hey, I had the same problem. Thanks for all the helpful suggestions. However in my case they didn't work.

I found the solution when I realized the icons next to my .py files did not include the python logo:

This is the icon for normal text files but normally the icon for python files look like this:

Here are some ways how this can be solved:

https://stackoverflow.com/questions/11687302/pycharm-not-recognizing-python-files

0

I have the problem as well but is solved when I restart with invalidating the cache. I work with very large projects and it seems to happen when I make major refactors that need reindexing or when I am making changes to the code mid execution in debug mode.  

0

I faced the same problem. I noticed it after I hastily/inadvertently clicked on one of those contextual lightbulb suggestions.

Tried invalidating caches, deleting .idea folder in project to no avail.

I solved it by resetting inspections to IDE defaults in settings. In my case it made sense because I don't really mess about with inspections. Also restarted with invalidate caches just to be sure but it may not have been necessary.

If you have some inspections adjustments of your own, you could then go back and turn them on or off as need be, on set them in context as you code.

Hope this helps.

1

Thank you, Victorkimuyu, after trying all the suggestions, yours about resetting to defaults was the only one that solved this very annoying problem!

1

I had this same problem with Pycharm professional 2021. None of the solutions suggested in this thread or a different thread (https://intellij-support.jetbrains.com/hc/en-us/community/posts/206598825-Code-Analysis-not-working-)  worked for me. However, the problem stopped after I updated Pycharm.

Edited to add: For what it's worth, the problem started after I edited a Cython .pyx file

0

What @Rodrigobraz said.  "Thank you, Victorkimuyu, after trying all the suggestions, yours about resetting to defaults was the only one that solved this very annoying problem!"

0

After moving to an arm64 apple machine, I'm having tons of trouble with code inspection. E.g. this

Clearly this shouldn't be an unresolved reference.  I have tried resetting defaults, invalidating caches, restarting, switching to new UI, switching back, and tried the 2023.2 EAP too. Nothing fixes this.

In this case, initially it was true that `tis` was not resolved because i hadn't added the param to the method signature.  But 5 minutes after adding it, it's still red.

Never ever had issues like this with an intel machine.

0

Hello, 

 

May I ask you to report this issue to 

https://youtrack.jetbrains.com/issues/PY , please attach a code example, steps to reproduce and 

logs folder zipped from ***Help | Collect logs and Diagnostic Data***

 

Thank you in advance. 

0

Please sign in to leave a comment.