pandas 不推荐使用 imp 模块以支持 importlib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43964166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:36:06  来源:igfitidea点击:

imp module is deprecated in favour of importlib

pythonpandaspython-importlibimp

提问by NotSoShabby

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

我在我的代码中使用了Pandas,而在Pandas中他们使用了小鬼结节。现在我收到以下错误/警告

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.

现在我做了一些搜索并意识到imp模块正在被importlib模块替换。我更新了Pandas,但没有用。我似乎不太可能需要更改 Panda 的包代码。

Any thoughts/fixes?

任何想法/修复?

回答by Khushhalm

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):

我也遇到了同样的问题,但在我的情况下,它与 sklearn 库有关,为了解决警告,这是我所做的(您也可以尝试这样做):

  1. Open the file with editing privileges named cloudpickle.pywhich is present at this location \sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
  2. replace import impand from imp import find_modulewith import importlibat the top of the file.
  3. find function named find_moduleand replace the line file, path, description = find_module(path)with file, path, description = importlib.utils.find_spec(path)
  1. 打开具有编辑权限的文件,该文件cloudpickle.py位于此位置\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
  2. 更换import impfrom imp import find_moduleimport importlib在文件的顶部。
  3. 找到名为函数find_module并更换线 file, path, description = find_module(path)file, path, description = importlib.utils.find_spec(path)

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

所以,综上所述,您必须更换的提imp moduleimportlib它引发错误的文件中。在您的情况下,该文件rewrite.py位于C:\Users\refaelc\AppData\Local\Continuum\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py