Pycharm, how to stop showing DeprecationWarning

My config: Python 3.9, Pycharm CE 2023.3.2, on Windows 10 Pro. Might be relevant: I’m using Qt Designer 6.4.2.

I did a Google search and found only 1 result that sort of matched, but didn’t help in the end.

I’m new to Python and still working on a tutorial. For the case of this tutorial I want to hide this warning each time the program runs:

DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead super().__init__() # Call __init__ of parent class.

Pycharm seems to have a way to stop/hide Python warnings. So in Pycharm I went to Settings, Editor, Inspections. Under Python section, unchecked “Deprecated function, class or …”

But the warning still shows when the program is run. How do I stop this warning from happening?

When I start developing real apps I will likely restore this warning but I have another 35 hours of tutorial to do still.

Thank you!

EDIT: Gemini AI says use @deprecated before a function call so I did this

class MainWindow(QMainWindow): # Put all widgets in this override class.
    @deprecated
    def __init__(self):
        super().__init__() # Call __init__ of parent class.
        self.initUI() # Our init function.

and still get this error:

c:\Users\MYUSER\PycharmProjects\pythonmasterclass>py ch423Qtable.py
  File "c:\Users\MYUSER\PycharmProjects\pythonmasterclass\ch423Qtable.py", line 14
    super().__init__() # Call __init__ of parent class.
    ^
SyntaxError: invalid syntax

Try the solutions found in this stackoverflow:

Two different things at play here:

  • PyCharm inspections are visual hints in PyCharm to warn you about potentially problematic code. These just affect how your code is highlighed in the editor. They don’t exist at runtime or affect the output of Python programs.
  • Python warnings on the other hand are part of Python. These exist at runtime and can affect the output of your program by e.g. writing to sys.stderr or being converted into exceptions.

The warning you’re seeing is a Python warning. To suppress it, you can try using the -W command line option, or configuring a warning filter at runtime with warnings.simplefilter/warnings.catch_warnings and friends.

By default, DeprecationWarning are ignored, so you probably have a configuration somewhere that’s causing it to be printed.

1 Like

Under Pycharm Settings, Build Execution Deployment, Python Console, in the “Interpreter options” I entered: -W ignore::DeprecationWarning

I still get the warnings. I did not restart Pycharm.

image

Ok I restarted Pycharm and reopened my project. The option in the image above is still there and I still get the warning.

Quite strange, I succeeded in two different ways:

  • Set the interpreter option -Wi::DeprecationWarning
  • Set the environment variable PYTHONWARNINGS=ignore

I’m using PyCharm CE 2023.3.3 with the new UI enabled, Python 3.12.1, on Linux.

Script:

from warnings import warn

if __name__ == '__main__':

  warn('Warning !', DeprecationWarning)

Normal output in PyCharm console (I edited the paths):

./venv/bin/python ./python_discuss.py 

./python_discuss.py:7: DeprecationWarning: Warning !
  warn('Warning !', DeprecationWarning)

Process finished with exit code 0

Output with either of the two solutions:

./venv/bin/python -Wi::DeprecationWarning ./python_discuss.py 

Process finished with exit code 0

Screenshots of how I set the environment variables and interpreter options:
Screenshot_2024-02-21_17-37-15
Screenshot_2024-02-21_17-38-14

Ok I had to put this in every (main) program but it works:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

While I’m doing a tutorial I will suppress this deprecation warning. While making actual apps I will allow it.

I’m new to Python and Pycharm. I think I see what is happening. It looks like a Debug configuration only applies to one Python file. But while doing this tutorial I will have 100s of chapters, one Python file per chapter. But I was looking for a global solution that I set once, and that worked for all files.

I don’t see a way to make a Debug config apply to all Python files.

While this didn’t work

I did find something that worked which I posted above.

Thanks for being patient while I learn all this.