이 Python 2.7 코드를 작동 시키려고합니다.Python 버전/혼동 가져 오기
https://github.com/slanglab/phrasemachine
나는 다운로드 GitHub의에서 REPO의 압축을 해제했습니다. 코드를 실행하려고하면 어떻게됩니까?
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError를이 : 어떤 모듈은
그래서, 나는 NLTK 모듈이 필요 NLTK 이름이 없습니다. 나는 여기에 설치되어있다 :
확실히, 파이썬 2는 nltk에 대해 모른다.
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
그러나 파이썬 3은 않습니다.
phrasemachine$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
Pip은 nltk가 이미 설치되어 있지만 3.5에 대해 알려줍니다.
$ sudo pip install -U nltk
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk-3.2.1-py3.5.egg
업데이트 10/10/16 : 2.7 버전의 Python을 brew를 통해 설치했는데, 2.7 pip를 제공합니다.
$ /usr/local/bin/pip --version
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
그런 다음 그 핍과 NLTK 설치 :
$ sudo /usr/local/bin/pip install -U nltk
Password:
The directory '/Users/me/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/me/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
Downloading nltk-3.2.1.tar.gz (1.1MB)
100% |████████████████████████████████| 1.1MB 683kB/s
Installing collected packages: nltk
Running setup.py install for nltk ... done
Successfully installed nltk-3.2.1
그것이 NLTK을 설치라고하지만 경고와 직결된다. 그리고 Python 2.7은 여전히 nltk를 임포트하지 못합니다.
$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError: No module named nltk
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
최종 업데이트! 필자는 Homebrew가 설치하는 사이트 패키지 디렉토리에 Python 2.7을 지적했으며 지금은 훌륭합니다! 두 파이썬 분포를 가지고 있기 때문에
>>> import sys
>>> sys.path.append('/usr/local/lib/python2.7/site-packages')
이 아마도 당신이 다운로드 한 새로운 양조 파이썬에 NLTK를 설치하는 시스템이 아닌 하나? 'which -a python'을 사용하여 어떤 비단뱀이 있는지 확인하십시오. 이 모든 일은 파이썬에 관한 최악의 경우 중 하나입니다. 'virtualenv'를 사용하여 크게 제거하십시오. – bananafish
이것으로 해결되었습니다! 모두 좋다. 당신의 도움을 주셔서 감사합니다! >>> import sys >>> sys.path.append ('/ usr/local/lib/python2.7/site-packages') – Sol
그리고 virtualenv에서 읽습니다. 고마워, 또! – Sol