Search code examples
pythondeprecation-warning

Deprecation Warnings: Distutils and netcdf_file


I get two deprecation warnings whenever I try running any python code. They are:

DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. MIN_CHEMFILES_VERSION = LooseVersion("0.9")

DeprecationWarning: Please use netcdf_file from the scipy.io namespace, the scipy.io.netcdf namespace is deprecated.

I am not sure how to use packaging.version instead of distuils and netcdf file. I am running python 3.8. I tried updating my virtualenv as suggested here: DeprecationWarning in Python 3.6 and 3.7 (with Pillow, distutils, imp) This doesn't work for me. Any help will be appreciated.

I could not find results for the second deprecation warning.


Solution

  • The

    DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    

    message is caused by the distutils module being overridden since setuptools 60.0.0. You would notice because the distutils.__file__ variable evals to .../site-packages/setuptools/_distutils/__init__.py, regardless of your python interpreter. Using any python 3.8 or 3.9 will not fix the warning unless your installation features setuptools<60. And even then, the warning can still be triggered by setting SETUPTOOLS_USE_DISTUTILS=local in the environment.

    See the breaking changes section in https://github.com/pypa/setuptools/blob/main/CHANGES.rst#v6000

    Workarounds to suppress this warnings can be either to downgrade to setuptools<60 or to start your python interpreter with the SETUPTOOLS_USE_DISTUTILS=stdlib environment variable. But I discourage any of these approaches, be ready for worse side effects if you go this way.

    Simply embrace the warning and try to contribute actual patches fixing this for any upstream library you were using before python 3.12 is released.