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
imp module is deprecated in favour of importlib
提问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 库有关,为了解决警告,这是我所做的(您也可以尝试这样做):
- Open the file with editing privileges named
cloudpickle.py
which is present at this location\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
- replace
import imp
andfrom imp import find_module
withimport importlib
at the top of the file. - find function named
find_module
and replace the linefile, path, description = find_module(path)
withfile, path, description = importlib.utils.find_spec(path)
- 打开具有编辑权限的文件,该文件
cloudpickle.py
位于此位置\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
- 更换
import imp
并from imp import find_module
与import importlib
在文件的顶部。 - 找到名为函数
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 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
所以,综上所述,您必须更换的提imp module
用importlib
它引发错误的文件中。在您的情况下,该文件rewrite.py
位于C:\Users\refaelc\AppData\Local\Continuum\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py