简体   繁体   English

Python 3.5.2:从textblob导入TextBlob:TypeError

[英]Python 3.5.2: from textblob import TextBlob : TypeError

I have installed Python 3.5.2 for windows - 32 bit. 我已经为Windows安装了Python 3.5.2-32位。 It includes PATH variable set procedure and required pip installation. 它包括PATH变量设置过程和所需的pip安装。

I'm trying to use TextBlob import for sentiment analysis, When I use import line in shell prompt it gives me TypeError : unorderable types str<> < int<> 我正在尝试使用TextBlob导入进行情感分析,当我在shell提示中使用导入行时,它给了我TypeError:无法排序的类型str <> <int <>

from textblob import TextBlob

I'm aware of the new changes in Python 3.x regarding the type change, but here I haven't included any single line of code, just trying to use import. 我知道Python 3.x中有关类型更改的新更改,但是在这里我没有包括任何一行代码,只是尝试使用import。

Python外壳

The problem is out on the version number,so maybe You could try to revise utils.py in the textblob folder.Add these script after the "try" in line 32: 问题出在版本号上,所以也许您可以尝试修改textblob文件夹中的utils.py。在第32行的“ try”之后添加以下脚本:
if not (x.isdigit()): 如果不是(x.isdigit()):
x='0' x ='0'
so your codes will be: 因此您的代码将是:

def _parse_version(version_string):
version = []
for x in version_string.split('.'):
    try:
        if not (x.isdigit()):
            x='0'
        version.append(int(x))
        #print(x)
    except ValueError:
        # x may be of the form dev-1ea1592
        version.append(x)
return tuple(version)

Resolved it. 解决了。 It was an issue with nltk lib. 这是nltk lib的问题。 I have followed below commands and it worked. 我按照下面的命令,它的工作。

32-bit binary installation 32位二进制安装

Install Numpy (optional): http://sourceforge.net/projects/numpy/files/NumPy/ (the version that specifies pythnon3.4)
Install NLTK: http://pypi.python.org/pypi/nltk

Mac/Unix Mac / Unix

Install NLTK: run sudo pip install -U nltk
Install Numpy (optional): run sudo pip install -U numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM