2016-10-09 3 views
0

Когда я пытаюсь импортировать NLTK в питона 3.5.2_2 я получаю следующее сообщение:Проблемы при вызове NLTK с Python 3.5.2_2?

>>> import nltk 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python3.5/site-packages/nltk/__init__.py", line 117, in <module> 
    from nltk.align import * 
    File "/usr/local/lib/python3.5/site-packages/nltk/align/__init__.py", line 15, in <module> 
    from nltk.align.ibm1 import IBMModel1 
    File "/usr/local/lib/python3.5/site-packages/nltk/align/ibm1.py", line 18, in <module> 
    from nltk.corpus import comtrans 
    File "/usr/local/lib/python3.5/site-packages/nltk/corpus/__init__.py", line 64, in <module> 
    from nltk.tokenize import RegexpTokenizer 
    File "/usr/local/lib/python3.5/site-packages/nltk/tokenize/__init__.py", line 65, in <module> 
    from nltk.tokenize.regexp import (RegexpTokenizer, WhitespaceTokenizer, 
    File "/usr/local/lib/python3.5/site-packages/nltk/tokenize/regexp.py", line 201, in <module> 
    blankline_tokenize = BlanklineTokenizer().tokenize 
    File "/usr/local/lib/python3.5/site-packages/nltk/tokenize/regexp.py", line 172, in __init__ 
    RegexpTokenizer.__init__(self, r'\s*\n\s*\n\s*', gaps=True) 
    File "/usr/local/lib/python3.5/site-packages/nltk/tokenize/regexp.py", line 119, in __init__ 
    self._regexp = compile_regexp_to_noncapturing(pattern, flags) 
    File "/usr/local/lib/python3.5/site-packages/nltk/internals.py", line 54, in compile_regexp_to_noncapturing 
    return sre_compile.compile(convert_regexp_to_noncapturing_parsed(sre_parse.parse(pattern)), flags=flags) 
    File "/usr/local/lib/python3.5/site-packages/nltk/internals.py", line 50, in convert_regexp_to_noncapturing_parsed 
    parsed_pattern.pattern.groups = 1 
AttributeError: can't set attribute 

Я попытался переустановить его с PIP3, и я все еще имею такой же вопрос ... Любая идея о том, как правильно установить NLTK в OSX ?, и как решить эту проблему ?.

+1

Если у вас есть 'nltk.align.ibm1.py', то кажется, что ваш' nltk' версия не обновляется. Попробуйте: https://gist.github.com/alvations/0ed8641d7d2e1941b9f9 – alvas

ответ

0

Это может работать

  1. Перейти к http://www.lfd.uci.edu/~gohlke/pythonlibs/
  2. Скачать NLTK-3,2,1-py2.py3-ни-any.whl
  3. Изменить папку в командной строке, где вы загрузили файл, что WHL
  4. Теперь написать C:/windows/python35/scripts/pip install nltk-3.2.1-py2.py3-none-any.whl

И, конечно, изменить эти пути, если они не соответствуют

+2

Можете ли вы объяснить, почему вы считаете, что неофициальная версия 'nltk' может решить проблему OP? – alexis

0

Я решил эту проблему путем модернизации с PIP3 NLTK и sklearn:

[email protected]:~$ pip3 install nltk --upgrade 
Collecting nltk 
    Downloading nltk-3.2.1.tar.gz (1.1MB) 
    100% |████████████████████████████████| 1.1MB 675kB/s 
Building wheels for collected packages: nltk 
    Running setup.py bdist_wheel for nltk ... done 
    Stored in directory: /Users/user/Library/Caches/pip/wheels/55/0b/ce/960dcdaec7c9af5b1f81d471a90c8dae88374386efe6e54a50 
Successfully built nltk 
Installing collected packages: nltk 
    Found existing installation: nltk 3.0.0 
    Uninstalling nltk-3.0.0: 
     Successfully uninstalled nltk-3.0.0 
Successfully installed nltk-3.2.1 
[email protected]:~$ python3 
Python 3.5.2 (default, Sep 28 2016, 18:08:09) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import nltk 
/usr/local/lib/python3.5/site-packages/sklearn/utils/fixes.py:55: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead 
    if 'order' in inspect.getargspec(np.copy)[0]: 
>>> 
[email protected]:~$ clear 
[email protected]:~$ pip3 install sklearn --upgrade 
Requirement already up-to-date: sklearn in /usr/local/lib/python3.5/site-packages 
Collecting scikit-learn (from sklearn) 
    Downloading scikit_learn-0.18-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (6.8MB) 
    100% |████████████████████████████████| 6.8MB 202kB/s 
Installing collected packages: scikit-learn 
    Found existing installation: scikit-learn 0.15.2 
    Uninstalling scikit-learn-0.15.2: 
     Successfully uninstalled scikit-learn-0.15.2 
Successfully installed scikit-learn-0.18 
[email protected]:~$ clear 
[email protected]:~$ python3 
Python 3.5.2 (default, Sep 28 2016, 18:08:09) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import nltk 
>>>