AttributeError: 'NoneType' object has no attribute 'loader'

创建日期:2020.03.03
修改日期:2020.03.04

文章目录

        • 1、问题导引
        • 2、解决办法
        • 3、参考连接

1、问题导引

(1)在Jupyter里面运行下面代码报错,是因为没有安装gensim。

from gensim import corpora, models, similarities
import gensim

(2)在Anaconda Prompt中安装gensim包

conda install -c conda-forge gensim

(3)然而出现问题

DEBUG menuinst_win32:create(320): Shortcut cmd is %windir%\System32\WindowsPowerShell\v1.0\powershell.exe, args are ['-ExecutionPolicy', 'ByPass', '-NoExit', '-Command', '"& \'C:\\ProgramData\\Anaconda3\\shell\\condabin\\conda-hook.ps1\' ; conda activate \'C:\\ProgramData\\Anaconda3\' "']
done
Error processing line 1 of C:\ProgramData\Anaconda3\lib\site-packages\matplotlib-3.1.0-py3.6-nspkg.pth:

  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site.py", line 168, in addpackage
      exec(line)
    File "", line 1, in <module>
    File "", line 568, in module_from_spec
  AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored

2、解决办法

这个错误是有关matplotlib-3.1.0的。在jupyter再次运行下面的代码,就没再报错。说明gensim安装成功了。

from gensim import corpora, models, similarities
import gensim

我关闭Anaconda Prompt后,再次重启。还是出现该错误。

Error processing line 1 of C:\ProgramData\Anaconda3\lib\site-packages\matplotlib-3.1.0-py3.6-nspkg.pth:

  Traceback (most recent call last):
    File "C:\ProgramData\Anaconda3\lib\site.py", line 168, in addpackage
      exec(line)
    File "", line 1, in <module>
    File "", line 568, in module_from_spec
  AttributeError: 'NoneType' object has no attribute 'loader'

经过参考别人连接,做了如下操作
C:\ProgramData\Anaconda3\Lib\site-packages目录下,把matplotlib-3.1.0-py3.6-nspkg.pth删掉。上述错误不再显示。
matplotlib-3.1.0-py3.6-nspkg.pth改成matplotlib-3.1.0-py3.6-nspkg.pth(ba-20200304),做个备份。

为什么这样,我不晓得。有人知道的话,请给我留言。谢谢!

3、参考连接

CSDN:【兼容调试】AttributeError: ‘NoneType’ object has no attribute ‘loader’

stackoverflow: AttributeError: ‘NoneType’ object has no attribute ‘loader’

你可能感兴趣的:(python)