setting `PYTHONWARNINGS` to disable python warnings seems to do nothing
Asked Answered
S

3

5

I'm currently running the openstack executable and it generates python deprecation warnings.

After some searching I did find this howto.

The relevant part is here:

Use the PYTHONWARNINGS Environment Variable to Suppress Warnings in Python

We can export a new environment variable in Python 2.7 and up. We can export PYTHONWARNINGS and set it to ignore to suppress the warnings raised in the Python program.

However, doing this:

PYTHONWARNINGS="ignore" openstack image show image name -f value -c id

does nothing, deprecation warnings are still displayed.

I've tried setting PYTHONWARNINGS to various things:

  • ignore
  • "ignore"
  • "all"
  • "deprecated"
  • "ignore::DeprecationWarning"
  • "error::Warning,default::Warning:has_deprecated_syntax"
  • "error::Warning"

but none of them seem to do anything.

I was able to work around the issue by appending 2>/dev/null to the end but I would like to know why PYTHONWARNINGS doesn't seem to do anything.

Sat answered 22/9, 2021 at 13:53 Comment(0)
M
6

PYTHONWARNINGS certainly does suppress python's warnings. Try running:

PYTHONWARNINGS="ignore" python -c "import warnings; warnings.warn('hi')"

But in this case you are not calling python, but openstack, which is apparently not inheriting the same environment. Without looking at the source I can't say why. It may even be explicitly settings the warning level, which will override anything you do before hand.

If you don't want to see errors, sending STDERR to /dev/null is the proper approach.

Melanosis answered 22/9, 2021 at 14:17 Comment(0)
S
1

For me the following command suppers the deprecation warning and I am not getting the warning any more.

$ export PYTHONWARNINGS="ignore::UserWarning"

Sinnard answered 24/7, 2023 at 16:52 Comment(0)
E
0

You possibly need to "export PYTHONWARNINGS" so it is avaialble to anything openstack invokes

Eleonoraeleonore answered 13/1, 2022 at 11:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.