How to get rid of 3rd collections.abc DeprecationWarning - python

My application is flooded with warnings from a 3rd package
transformers/modeling_deberta.py:18: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
from collections import Sequence
How can I suppress those warnings?
I've tried:
export PYTHONWARNINGS="ignore::DeprecationWarning"
warnings.filterwarnings(action="ignore")
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module=r".*transformers.*")
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module=r".*collections.*")
warnings.filterwarnings(action="ignore", message=r".*collections.abc.*")
Update
The following options are not feasible:
Remove the 3rd package that generates those warnings. It is irreplaceable.
Downgrade to python 3.3
Maybe I should just wait for the 3rd package to upgrade. Just wonder if there is any other option to suppress specific 3rd party warnings in python.

The warning tells you that you are getting some resources from a location which was correct prior to Python 3.3 and will not work at all starting from Python 3.9. You are using a Python version between 3.3 and 3.9, which means that this will still work for you for the time being, but you will need to refactor your code so you import ABCs from collections.abc instead of from collections. Unless you refactor your code in the manner the error suggests, you will be stuck with Python versions prior to 3.9, which limits your possibilities, will disallow the usage of any goodies implemented after those versions and will increasingly see libraries incompatible with your project due to they being too modern for your project.
You can get rid of the warnings by downgrading your project to a Python version prior to 3.3, but that's a direction you should strive to avoid if possible. The best solution is to refactor your project to comply to the terms of modern Python versions and if you use packages that prevent you from doing so, then you might want to upgrade those packages. If there is no upgrade that would solve this issue, then it is well worth asking your question whether it is a higher cost to implement their functionality in a more modern way in terms of labor on your part or is it a higher cost in terms of technological shortage if you get stuck with old Python versions.

I found my answer from here
Solution: make sure the following code runs before the 3rd package import.
If multiprocessing is used, the code has to be called in each process.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
from collections import Sequence

Related

Why is kociemba python module not working correctly?

I'm trying to build a rubik's cube solver and I'm using kociemba module. I had some problems with installation so I downloaded it manually from GitHub - https://github.com/muodov/kociemba. Now I'm testing it but I'm getting an error that I don't understand. Answer if you can help, thanks!
This is the test code:
import kociemba
kociemba.solve('DRLUUBFBRBLURRLRUBLRDDFDLFUFUFFDBRDUBRUFLLFDDBFLUBLRBD')
And I'm getting this output:
No module named 'kociemba.ckociembawrapper'
C:\Users\Paweł\AppData\Local\Programs\Python\Python39\lib\site-
packages\kociemba\__init__.py:21: SlowContextWarning: Native version of the package
is not available. We have to fallback to pure-Python implementation of the
algorithm, which is usually many times slower. If performance is important to you,
check official project page for a native implementation:
https://github.com/muodov/kociemba
warnings.warn("Native version of the package is not available. "

Not able to import from `gensim.summarization` module in Django

I have included the 2 import statements in my views.py
from gensim.summarization.summarizer import summarizer
from gensim.summarization import keywords
However, even after I installed gensim using pip, I am getting the error:
ModuleNotFoundError: No module named 'gensim.summarization'
The summarization code was removed from Gensim 4.0. See:
https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#12-removed-gensimsummarization
12. Removed gensim.summarization
Despite its general-sounding name, the module will not satisfy the
majority of use cases in production and is likely to waste people's
time. See this Github
ticket for
more motivation behind this.
If you need it, you could try:
installing the older gensim version; or…
copy the source code out to your own local module
However, I expect you'd likely be disappointed by its inflexibility and how little it can do.
It was only extractive summarization - choosing a few key sentences from those that already exist. That only gives impressive results when the source text was already well-written in an expository style mixing high-level overview sentences with separate detail sentences. And, its method of analyzing/ranking words was very crude & hard-to-customize – totally unconnected to the more generic/configurable/swappable approaches used elsewhere in Gensim or in other text libraries.
You can run pip freeze within your environment to ensure it is installed here.
If it is, then you should check naming of any modules or files you have in your directory to ensure there are no conflicts.
I had the same issue
As per Gensim’s Github changelog 188, gensim.summarization module has been removed in versions Gensim 4.x as it was an unmaintained third-party module.
To continue using gensim.summarization, you will need to downgrade the version of Gensim in the requirements.txt file by replacing it with gensim==3.8.3 or an older version.

The sklearn.* module is deprecated in version 0.22 and will be removed in version 0.24

I am migrating a piece of software from Python 2.7 to Python 3.
One problem that arises is:
The sklearn.neighbors.kde module is deprecated in version 0.22 and
will be removed in version 0.24. The corresponding classes / functions
should instead be imported from sklearn.neighbors. Anything that
cannot be imported from sklearn.neighbors is now part of the private
API.
I am not sure which line causes this, and not sure if it is an error or a warning, and what are the implications.
On python 2.7 everything works fine.
How do I get rid of this?
It will work until you update your scikit/sklearn version. Then the Kernel Density package will not run any more. You still have time to search for similar modules if you want to update your version.
But you can also set up different environments with different versions. Thus, if you need this module just start an environment and don't upgrade your sklearn version in this environment.
It's just a warning, for now -- until you upgrade sklearn to version 0.24. Then your code will need to be modified before it works. It's giving you a heads-up about this, so you can fix your code ahead of time. The modifications described below should work with your current version; you don't need to wait to upgrade before changing your code (at least, that's how these deprecation warnings usually work).
The corresponding classes / functions should instead be imported from sklearn.neighbors.
If I read this message correctly, it's saying that if you're using a function like sklearn.neighbours.kde.some_function() in your code now, you need to change it to sklearn.neighbours.some_function().
Anything that cannot be imported from sklearn.neighbors is now part of the private API.
This seems to be saying that there may be some functions that will no longer be available to you, even using the modification above.

How can I stop numpy_1.8 from masking numpy_1.10?

I had thought I was using the most recent version of numpy (1.10) At least, when I run pip list I see numpy (1.10.4). However, when I get into the python interpreter and type
import numpy
numpy.__version__
I see
'1.8.2'
I expect that the 1.8.2 got installed sometime after the 1.10 version, because I've recently installed some new packages and I now when I run some code that used to work, I get this error:
RuntimeError: module compiled against API version a but this version of numpy is 9
In OpenCV 2.4.8: module compiled against API version 9 the accepted answer mentioned that the numpy team refers to version 1.8 as numpy version 9. So, I think that I was originally using numpy_1.10, and somehow got numpy_1.8 installed.
My first question is How did this happen and how can I guard against it?
I also want to know how I can stop numpy_1.8 from blocking 1.10. My initial thought was to remove numpy_1.8 using apt-get, but that would've removed many other packages that are dependent upon 1.8.
I'd be tempted to just use rm to get rid of the 1.8 version, but am worried that those other packages would be affected.
My second thought is to change sys.path to make certain the 1.10 version is seen before the 1.8 version. So far, I'm not using PYTHONPATH. Is there a way to change sys.path without using PYTHONPATH? Is this a reasonable approach to take?
The simplest thing to do is to remove your NumPy 1.8 installation. Look at numpy.__file__ to find where your 1.8 installation is, then delete the directory.
Alternatively, as you mentioned and if you don't want to delete 1.8, you could also change your path. Something like this ought to do it:
import sys
sys.path.insert(3, '<path_to_your_NumPy_1.10_install>')
I've inserted at position 3 so that you keep things like '' at the top, but you could modify this as needed.

sys.path.append doesn't work with Python 3.x

I have Blender 2.66a which is an application that offers Python 3.3 APIs, On my system I have an installation of Python 3.2 with several modules that I wish to use inside Blender, I tried both
sys.path.append(r"/usr/lib/python3.2/")
sys.path.append("/usr/lib/python3.2/")
and this commands gives no errors, infact even the autocomplete feature works and new modules are indexed, so i tried
import tkinter
but this generates the following error
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "/usr/lib/python3.2/tkinter/__init__.py", line 42, in <module>
raise ImportError(str(msg) + ', please install the python-tk package')
ImportError: No module named '_tkinter', please install the python-tk package
and I don't get the point of this error because it fails to load a module that it's there asking me to install the same module because that module is not installed ( ? ).
What can cause this obscure problem ?
EDIT
the tkinter module works from the gnome-terminal
If I got you right, you're using Python 3.3 from Blender but try to include the 3.2 standard library. This is bound to give you a flurry of issues, you should not do that. Find another way. It's likely that Blender offers a way to use the 3.3 standard library (and that's 99% compatible with 3.2). Pure-Python third party library can, of course, be included by fiddling with sys.path.
The specific issue you're seeing now is likely caused by the version difference. As people have pointed out in the comments, Python 3.3 doesn't find the _tkinter extension module. Although it is present (as it works from Python 3.2), it is most likely in a .so file with an ABI tag that is incompatible with Blender's Python 3.3, hence it won't even look at it (much like a module.txt is not considered for import module). This is a good thing. Extension modules are highly version-specific, slight ABI mismatches (such as between 3.2 and 3.3, or two 3.3 compiled with different options) can cause pretty much any kind of error, from crashes to memory leaks to silent data corruption or even something completely different.
You can verify whether this is the case via import _tkinter; print(_tkinter.__file__) in the 3.2 shell. Alternatively, _tkinter may live in a different directory entirely. Adding that directory won't actually fix the real issue outlined above.

Categories