我使用Pycharm编写代码。
代码语言:javascript运行复制import importlib,sys
importlib.reload(sys)
from snownlp import SnowNLP
import pandas as pd
text=pd.read_excel(u'comment-label.xlsx',header=0) #读取excel表格数据
text0=text.iloc[:,0] #提取所有数据
text1=[i.decode('utf-8')for i in text0] #转码
sent=[SnowNLP(i).sentiments for i in text1] #遍历每条评论进行预测
newsenti=[]
for i in sent:
if(i>=0.5):
newsenti.append(1)
else:
newsenti.append(-1)
text['predict'] = newsenti
counts=0
for j in range(len(text.iloc[:,0])): #遍历所有标签,将预测标签和实际标签进行比较,相同则判断正确。
if text.iloc[j,2]==text.iloc[j,1]:
counts+=1
print (u"准确率为:%f"%(float(counts)/float(len(text)))) #输出本次预测的准确率并返回错误
代码语言:javascript运行复制Traceback (most recent call last):
File "D:\程序软件\pycharm\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1664, in
main()
File "D:\程序软件\pycharm\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\程序软件\pycharm\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\程序软件\pycharm\PyCharm Community Edition 2018.1.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/程序软件/pycharmProject/test/Sentiment_analysis/assessment.py", line 4, in
from snownlp import SnowNLP
File "D:\程序软件\pycharmProject\test\Sentiment_analysis\snownlp.py", line 4, in
from snownlp import SnowNLP
ImportError: cannot import name 'SnowNLP'
Process finished with exit code 1但是我已经安装了'snownlp‘'snownlp ' installing path 包
昨天我可以用from snownlp import SnowNLP很好地调试其他代码,没有看到这个错误,但现在其他代码也遇到了同样的错误。
我在Pycharm中重新安装了snownlp包,但它不起作用。
我该怎么做呢?