imp module is deprecated in favour of importlib

NotSoShabby picture NotSoShabby · May 14, 2017 · Viewed 11.8k times · Source

I'm using pandas in my code and in pandas they use the imp nodule. Now I get the following error/warnning

C:\Users\refaelc\AppData\Local\Temp\collection_id-96deaf03-9b39-46c0-a843-63f6101481c1-5289121858290797008.csv
Step07: Compare the downloaded and the template files
C:\Users\refaelc\AppData\Local\Continuum\Anaconda3\lib\importlib\_bootstrap.py:205: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  return f(*args, **kwds)
C:\Users\refaelc\AppData\Local\Continuum\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Item is missing from collections - int

Now I did some searching and realized that the imp module is being replaced by the importlib module. I updated Panda and that didn't work. It seemed unlikely that I'll need to change Panda's package code.

Any thoughts/fixes?

Answer

Khushhalm picture Khushhalm · Oct 13, 2018

I was also facing the same issue but in my case, it was with sklearn Library and in order to fix the warning this is what I did (you can also try this):

  1. Open the file with editing privileges named cloudpickle.py which is present at this location \sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
  2. replace import imp with import importlib at the top of the file.
  3. find function named find_module and replace the line file, path, description = imp.find_module(part, path) with file, path, description = importlib.utils.find_spec(path)

So, in conclusion, you have to replace mention of imp module with importlib in the file which is throwing the error. In your case the file is rewrite.py present at C:\Users\refaelc\AppData\Local\Continuum\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py