熊猫过去在我的计算机上运行良好。但是今天突然间,当我尝试将其导入脚本(版本pip upgrade.py)时,它弹出一条错误消息:
import pandas as pd
print pd.__version__
它弹出:
AttributeError: 'module' object has no attribute 'isclass'
我尝试卸载,重新安装熊猫的更新版本。
我用Google搜索并尝试了其他一些更改。它说问题与NLTK有关,因此我卸载了NLTK,但问题仍然存在。我也尝试更改环境变量,但无济于事。
出了什么问题,我该如何纠正?
谢谢。
这是整个错误消息
Traceback (most recent call last):
File "C:\Python27\Working Scripts\Version pip upgrade.py", line 1, in <module>
import pandas as pd
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "C:\Python27\lib\site-packages\pandas\compat\__init__.py", line 39, in <module>
import inspect
File "C:\Python27\lib\inspect.py", line 39, in <module>
import tokenize
File "C:\Python27\Working Scripts\tokenize.py", line 3, in <module>
import nltk
File "C:\Python27\lib\site-packages\nltk\__init__.py", line 115, in <module>
from nltk.decorators import decorator, memoize
File "C:\Python27\lib\site-packages\nltk\decorators.py", line 187, in <module>
@decorator
File "C:\Python27\lib\site-packages\nltk\decorators.py", line 165, in decorator
if inspect.isclass(caller):
AttributeError: 'module' object has no attribute 'isclass'
答案 0 :(得分:1)
我认为您正在用tokenize
遮盖C:\Python27\Working Scripts\tokenize.py
模块。您可以尝试更改其名称吗?
内部inspect
导入python内置模块tokenize
,但似乎您要运行的脚本旁边有tokenize.py
。
Python将首先搜索要导入当前目录的模块。在您的情况下,它会找到一个实际上需要python内置模块之一的位置。