Nltk: 닀쀑 μ²˜λ¦¬μ™€ nltkκ°€ ν•¨κ»˜ 잘 μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2015λ…„ 04μ›” 16일  Β·  22μ½”λ©˜νŠΈ  Β·  좜처: nltk/nltk

μ†”μ§νžˆμ΄ λ¬Έμ œλŠ” ν˜ΈκΈ°μ‹¬λ§ŒνΌ μ‹¬κ°ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. NLTKλ₯Ό κ°€μ Έμ˜¬ λ•Œ λͺ¨λ“  Python ν•˜μœ„ ν”„λ‘œμ„ΈμŠ€κ°€ λ„€νŠΈμ›Œν¬ ν˜ΈμΆœμ—μ„œ 쑰기에 μ’…λ£Œλœλ‹€λŠ” 것을 λ°œκ²¬ν–ˆμŠ΅λ‹ˆλ‹€. 예제 μ½”λ“œ :

from multiprocessing import Process
import nltk
import time


def child_fn():
    print "Fetch URL"
    import urllib2
    print urllib2.urlopen("https://www.google.com").read()[:100]
    print "Done"


while True:
    child_process = Process(target=child_fn)
    child_process.start()
    child_process.join()
    print "Child process returned"
    time.sleep(1)

κ°€μ Έμ˜¨ NLTK둜 μ‹€ν–‰ν•˜λ©΄ urlopen () 호좜이 μ‹€ν–‰λ˜μ§€ μ•ŠλŠ” 것을 λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€. import nltk 쀄을 주석 μ²˜λ¦¬ν•˜λ©΄ μ œλŒ€λ‘œ μ‹€ν–‰λ©λ‹ˆλ‹€.

μ™œ?

* νŽΈμ§‘ : 이것은 Python 2 μš©μž…λ‹ˆλ‹€. 아직 3μ—μ„œ ν…ŒμŠ€νŠΈν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.

admin bug inactive multithread / multiprocessing pythonic

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

λ‚˜λŠ” nltk에 λŒ€ν•΄ 믿을 수 없을 μ •λ„λ‘œ μ΅μˆ™ν•˜μ§€ μ•Šμ§€λ§Œ ν…ŒμŠ€νŠΈκ°€ 톡과 / μ‹€νŒ¨ν•œ 원인을 ν™•μΈν•˜κΈ° μœ„ν•΄ μ•½κ°„ λˆˆμ„ λ©€κ²Œν–ˆλ‹€. ν…ŒμŠ€νŠΈλ₯Ό ν†΅κ³Όν•˜κΈ° μœ„ν•΄ __init__.py νŒ¨ν‚€μ§€μ— μˆ˜ν–‰ν•΄μ•Όν•˜λŠ” μž‘μ—…μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.


μ„ΈλΆ€ 정보 (ν™•μž₯ν•˜λ €λ©΄ 클릭)

###########################################################
# TOP-LEVEL MODULES
###########################################################

# Import top-level functionality into top-level namespace

from nltk.collocations import *
from nltk.decorators import decorator, memoize
# from nltk.featstruct import *
# from nltk.grammar import *
from nltk.probability import *
from nltk.text import *
# from nltk.tree import *
from nltk.util import *
from nltk.jsontags import *

# ###########################################################
# # PACKAGES
# ###########################################################

# from nltk.chunk import *
# from nltk.classify import *
# from nltk.inference import *
from nltk.metrics import *
# from nltk.parse import *
# from nltk.tag import *
from nltk.tokenize import *
from nltk.translate import *
# from nltk.sem import *
# from nltk.stem import *

# Packages which can be lazily imported
# (a) we don't import *
# (b) they're slow to import or have run-time dependencies
#     that can safely fail at run time

from nltk import lazyimport
app = lazyimport.LazyModule('nltk.app', locals(), globals())
chat = lazyimport.LazyModule('nltk.chat', locals(), globals())
corpus = lazyimport.LazyModule('nltk.corpus', locals(), globals())
draw = lazyimport.LazyModule('nltk.draw', locals(), globals())
toolbox = lazyimport.LazyModule('nltk.toolbox', locals(), globals())

# Optional loading

try:
    import numpy
except ImportError:
    pass
else:
    from nltk import cluster

# from nltk.downloader import download, download_shell
# try:
#     from six.moves import tkinter
# except ImportError:
#     pass
# else:
#     try:
#         from nltk.downloader import download_gui
#     except RuntimeError as e:
#         import warnings
#         warnings.warn("Corpus downloader GUI not loaded "
#                       "(RuntimeError during import: %s)" % str(e))

# explicitly import all top-level modules (ensuring
# they override the same names inadvertently imported
# from a subpackage)

# from nltk import ccg, chunk, classify, collocations
# from nltk import data, featstruct, grammar, help, inference, metrics
# from nltk import misc, parse, probability, sem, stem, wsd
# from nltk import tag, tbl, text, tokenize, translate, tree, treetransforms, util


ν₯λ―Έλ‘­κ²Œλ„ λͺ¨λ“  λΉ„ν™œμ„±ν™” 된 μˆ˜μž…μ€ ꢁ극적으둜 tkinter μˆ˜μž…μœΌλ‘œ λŒμ•„κ°€λŠ”λ° 이것이 κ·Όλ³Έ 원인 import nltk λ₯Ό import tkinter 둜 λ°”κΎΈλ©΄ tkinterλ₯Ό μ°Έμ‘°ν•˜λŠ” 맀우 μœ μ‚¬ν•œ 좩돌 λ³΄κ³ μ„œκ°€ ν‘œμ‹œλ©λ‹ˆλ‹€.

λ‚΄κ°€ μ•Œ 수 μžˆλ“―μ΄μ΄ νŒ¨ν‚€μ§€λŠ” tkinter 직접 κ°€μ Έμ˜΅λ‹ˆλ‹€.

  • nltk.app
  • nltk.draw
  • nltk.sem

μœ„μ˜ κΈ°λ³Έ νŒ¨ν‚€μ§€ __init__ λ³€κ²½ μ‚¬ν•­μ—μ„œ λ¬Έμ œκ°€μžˆλŠ” κ°€μ Έ μ˜€κΈ°μ™€ tkinter κ°€μ Έ 였기λ₯Ό μΆ”μ ν•˜λŠ” 방법

  • nltk.featstruct ( sem )
  • nltk.grammar ( featstruct )
  • nltk.tree ( grammar )
  • nltk.chunk ( chunk.named_entity > tree )
  • nltk.parse ( parse.bllip > tree )
  • nltk.tag ( tag.stanford > parse )
  • nltk.classify ( classify.senna > tag )
  • nltk.inference ( inference.discourse > sem , tag )
  • nltk.stem ( stem.snowball > corpus > corpus.reader.timit > tree )

λͺ¨λ“  22 λŒ“κΈ€

μ˜ˆμ™Έκ°€ μžˆμŠ΅λ‹ˆκΉŒ?

μ•„λ‹ˆ. import urllib2; print... μ£Όμœ„μ— try .. except: μ ˆμ„ λ‘μ—ˆμ§€λ§Œ 아무것도 얻지 λͺ»ν–ˆμŠ΅λ‹ˆλ‹€.

λ‚˜λŠ” λ˜‘κ°™μ€ λ¬Έμ œμ— μ§λ©΄ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. 여기에 λ§ν¬ν•˜λŠ” 데 유용 ν•  μˆ˜μžˆλŠ” SO μ§ˆλ¬Έμ„ 방금 μ—΄μ—ˆμŠ΅λ‹ˆλ‹€. http://stackoverflow.com/questions/30766419/python-child-process-silently-crashes-when-issuing-an-http-request

μžμ‹ ν”„λ‘œμ„ΈμŠ€λŠ” μ‹€μ œλ‘œ μΆ”κ°€ 톡지없이 쑰용히 μΆ©λŒν•©λ‹ˆλ‹€.

@ oxymor0n에 λ™μ˜ν•˜μ§€

The child process is indeed crashing silently without further notice.

nltk, gunicorn (preforkλ₯Ό ν†΅ν•΄λ‘œλ“œ 된 nltk 포함) 및 flask의 μ‘°ν•©μ—μ„œλ„μ΄ λ¬Έμ œκ°€ λ°œμƒν•©λ‹ˆλ‹€.

nltk κ°€μ Έ 였기λ₯Ό μ œκ±°ν•˜λ©΄ λͺ¨λ“  것이 μž‘λ™ν•©λ‹ˆλ‹€. nltkλ₯Ό μ œμ™Έν•˜κ³ .

/ cc @escherba

@ninowalker , @ oxymor0n μ΄μƒν•©λ‹ˆλ‹€. λ‚΄ ν”„λ‘œμ„ΈμŠ€κ°€ μ½”λ“œλ‘œ 잘 μ‹€ν–‰λ©λ‹ˆλ‹€.

Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content
Done
Child process returned

그게 μ˜ˆμƒλ˜λŠ” κ²°κ³Ό μ£ ?

이것도 λ‚΄ μš”μ²­μ„ 깨지 μ•ŠμŠ΅λ‹ˆλ‹€.

alvas<strong i="13">@ubi</strong>:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from multiprocessing import Process
>>> import requests
>>> from pprint import pprint
>>> Process(target=lambda: pprint(
...         requests.get('https://api.github.com'))).start()
>>> <Response [200]>

>>> import nltk
>>> Process(target=lambda: pprint(
...         requests.get('https://api.github.com'))).start()
>>> <Response [200]>

λ‚˜λŠ” μ‚¬μš©ν•˜κ³ μžˆλ‹€ :

  • 파이썬 2.7.6
  • nltk 3.0.3
  • μš°λΆ„νˆ¬ 14.04

@Hiestaa 와 λ™μΌν•œ λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. nltkλ₯Ό κ°€μ Έ μ˜€λŠ” λ„μš°λ―Έ 파일 string_util.python이 μžˆμ§€λ§Œ 닀쀑 ν”„λ‘œμ„ΈμŠ€ 크둀러λ₯Ό μ‹œμž‘ν•˜κΈ° μœ„ν•΄ 닀쀑 처리 λͺ¨λ“ˆμ„ μ‚¬μš©ν•˜λŠ” κΈ°λ³Έ Python νŒŒμΌμ—μ„œλŠ” μ‚¬μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 증상은 μžμ‹ ν”„λ‘œμ„ΈμŠ€κ°€ λ§‰νžˆκ³  였λ₯˜ λ©”μ‹œμ§€ (μ˜ˆμ™Έ λ©”μ‹œμ§€λ„ μ•„λ‹˜)κ°€ μ—†λ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.
nltk κ΄€λ ¨ κ°€μ Έ 였기 및 ν•¨μˆ˜λ₯Ό 주석 처리 ν•œ ν›„ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

μ„ΈλΆ€:
운영체제 : Yosemite 10.10.5
Python : 2.7.10
νŽ˜μ΄μ§€ μ½˜ν…μΈ  검색 : μ²˜μŒμ—λŠ” urllib2λ₯Ό μ‚¬μš©ν•œ λ‹€μŒ λ‚˜μ€‘μ— μš”μ²­μœΌλ‘œ μ „ν™˜ν–ˆμŠ΅λ‹ˆλ‹€.

이것은 맀우 μ‹¬κ°ν•œ 버그이며 λˆ„κ΅°κ°€κ°€ κ°œμž…ν•˜μ—¬ μˆ˜μ •ν•  수 있기λ₯Ό λ°”λžλ‹ˆλ‹€. 감사!

ν”„λ‘œλ•μ…˜ μˆ˜μ€€μ˜ NLPλ₯Ό μˆ˜ν–‰ν•˜λŠ” 경우 이것이 μ‹¬κ°ν•œ 문제라고 μƒκ°ν•©λ‹ˆλ‹€. μš°λ¦¬λŠ” Rq (http://python-rq.org/) μž‘μ—…μžλ₯Ό μ‚¬μš©ν•˜μ—¬ μ—¬λŸ¬ NLP νŒŒμ΄ν”„ 라인을 μ‹€ν–‰ν•©λ‹ˆλ‹€. λ„€νŠΈμ›Œν¬ ν˜ΈμΆœμ„ ν•  λ•Œ 쑰용히 μ£½μŠ΅λ‹ˆλ‹€. 곧 μˆ˜μ •λ˜κΈ°λ₯Ό λ°”λžλ‹ˆλ‹€. 감사!

@sasinda : nltk-dev 메일 λ§λ¦¬μŠ€νŠΈμ— μ „ν™”λ₯Ό 걸어이 λ¬Έμ œμ— λŒ€ν•΄ 관심을 κ°€μ§ˆ 수 μžˆλŠ”μ§€ μ•Œμ•„λ³΄μ„Έμš”.

@sasinda Rqκ°€ μ •ν™•νžˆ μ–΄λ–»κ²Œ μž‘λ™ν•˜λŠ”μ§€ 잘 λͺ¨λ₯΄κ² μ§€λ§Œ ν”„λ‘œλ•μ…˜ μˆ˜μ€€μ˜ NLP ν”„λ‘œμ νŠΈμ—μ„œ 각 ν”„λ‘œμ„ΈμŠ€λ₯Ό λΆ„λ¦¬λ˜κ³  격리 된 Python μΈν„°ν”„λ¦¬ν„°μ—μ„œ μ‹œμž‘ν•˜μ—¬ μ‹œμž‘μ‹œ μƒμ„±ν•˜λŠ” μ‰˜ 슀크립트λ₯Ό μ‚¬μš©ν•˜μ—¬μ΄ 문제λ₯Ό ν•΄κ²°ν•  μˆ˜μžˆμ—ˆμŠ΅λ‹ˆλ‹€. 이 경우 νŒŒμ΄μ¬μ€ 포크 ν•  ν•„μš”κ°€ μ—†μœΌλ©° nltkμ—μ„œ μžλ™ 좩돌이 λ°œμƒν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. κ·Έλ™μ•ˆ 도움이 될 수 μžˆμŠ΅λ‹ˆλ‹€.

ν•¨μˆ˜ μˆ˜μ€€μ—μ„œ κ°€μ Έ 였기λ₯Ό μˆ˜ν–‰ν•˜λ©΄ λ¬Έμ œκ°€ λ°œμƒν•˜μ§€ μ•ŠλŠ” κ²ƒμœΌλ‘œ λ‚˜νƒ€λ‚¬μŠ΅λ‹ˆλ‹€.

즉, λ‹€μŒκ³Ό 같이 μž‘λ™ν•©λ‹ˆλ‹€.

def split(words):
    import nltk
    return nltk.word_tokenize(words)

그리고 이것은 :

import nltk
def split(words):
    return nltk.word_tokenize(words)

@mpenkovμ—κ²Œ κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€. λ¬Έμ œκ°€ ν•΄κ²° λ˜μ—ˆμŠ΅λ‹ˆκΉŒ?

@stevenbird λ‚˜λŠ” κ·Έλ ‡κ²Œ μƒκ°ν•˜μ§€ μ•ŠλŠ”λ‹€. ν•΄κ²° λ°©λ²•μ΄μ§€λ§Œ μˆ˜μ •μ΄ μ•„λ‹™λ‹ˆλ‹€.

IMHO, 타사 라이브러리λ₯Ό κ°€μ Έ μ˜€λŠ” 것이 Python ν‘œμ€€ 라이브러리 ꡬ성 μš”μ†Œλ₯Ό μ†μƒμ‹œν‚€λŠ” 경우 μ–΄λ”˜κ°€μ—μ„œ λΆ€μ •ν•œ 일이 λ°œμƒν•˜κ³  μˆ˜μ •ν•΄μ•Όν•©λ‹ˆλ‹€.

@mpenkov λ‚˜λŠ” 이것이 μ™œ μž‘λ™ν•˜λŠ”μ§€ μ™„μ „νžˆ λͺ¨λ₯΄κ² μ§€λ§Œ 여기에 λ‚΄κ°€ 찾은 또 λ‹€λ₯Έ ν•΄κ²° 방법이 μžˆμŠ΅λ‹ˆλ‹€. λΆ€λͺ¨ ν”„λ‘œμ„ΈμŠ€μ—μ„œ μ˜€ν”„λ„ˆλ₯Ό κ΅¬μΆ•ν•˜λ©΄ λ¬Έμ œκ°€ ν•΄κ²°λ˜λŠ” κ²ƒμœΌλ‘œ λ³΄μž…λ‹ˆλ‹€. @ oxymor0n 의 μ›λž˜ μ½”λ“œ μˆ˜μ • :

from multiprocessing import Process
import nltk
import time
import urllib2

# HACK
urllib2.build_opener(urllib2.HTTPHandler())

def child_fn():
    print "Fetch URL"
    import urllib2
    print urllib2.urlopen("https://www.google.com").read()[:100]
    print "Done"


while True:
    child_process = Process(target=child_fn)
    child_process.start()
    child_process.join()
    print "Child process returned"
    time.sleep(1)

@mpenkov @ninowalker , @ oxymor0n @sasinda @wenbowang μ—¬λŸ¬λΆ„ λͺ¨λ‘ μ—¬μ „νžˆ 같은 λ¬Έμ œμ— μ§λ©΄ν•˜κ³  μžˆμŠ΅λ‹ˆκΉŒ?

λ‚΄ μ»΄ν“¨ν„°μ—μ„œ 문제λ₯Ό 볡제 ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

from multiprocessing import Process
import nltk
import time

def child_fn():
    print "Fetch URL"
    import urllib2
    print urllib2.urlopen("https://www.google.com").read()[:100]
    print "Done"


while True:
    child_process = Process(target=child_fn)
    child_process.start()
    child_process.join()
    print "Child process returned"
    time.sleep(1)

λ‚˜μ—κ²Œ μ€€λ‹€ :

Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-SG"><head><meta cont
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-SG"><head><meta cont
Done
Child process returned
Fetch URL
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-SG"><head><meta cont
Done

λ‚˜λŠ” :

  • 파이썬 2.7.12
  • NLTK 3.2.5
  • μš°λΆ„νˆ¬ 16.04.3

@alvations 이 문제λ₯Ό 발견 ν•œ 지 μ˜€λž˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
이 λ¬Έμ œκ°€μžˆλŠ” ν”„λ‘œμ νŠΈ κΈ°λ°˜μ„ μžŠμ–΄ λ²„λ €μ„œ μ—¬μ „νžˆ λ¬Έμ œκ°€ μžˆλŠ”μ§€ μ—¬λΆ€λ₯Ό 말할 수 μ—†μ—ˆμŠ΅λ‹ˆλ‹€.
μ£„μ†‘ν•©λ‹ˆλ‹€!

@alvations 저도이 νŠΉμ • 문제둜 인해 고톡을 κ²ͺ은 ν”„λ‘œμ νŠΈλ₯Ό κΈ°μ–΅ν•˜μ§€ λͺ»ν•©λ‹ˆλ‹€.

λ‚΄ μ»΄ν“¨ν„°μ—μ„œ μ½”λ“œλ₯Ό μ‹€ν–‰ν–ˆμ§€λ§Œ 문제λ₯Ό 볡제 ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

파이썬 2.7.12
nltk 3.2.1
macOS 10.12.6

@alvations λ‚˜λ„ 더 이상 κ·Έ ν”„λ‘œμ νŠΈμ—μ„œ μΌν•˜κ³  μžˆμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μ΄λŸ¬ν•œ ν•΄κ²° 방법 쀑 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€.
μ½”λ“œλ₯Ό μ‹œλ„ν–ˆμ§€λ§Œ μ—¬μ „νžˆ ν•˜μœ„ ν”„λ‘œμ„ΈμŠ€κ°€ μ„Έκ·Έλ¨ΌνŠΈ 였λ₯˜ (μ’…λ£Œ μ½”λ“œ 11)둜 μ’…λ£Œλ©λ‹ˆλ‹€ (μ’…λ£Œ : urllib2.urlopen ( "https://www.google.com") .read () [: 100]).

κ·Έλž˜λ„ urllib3 (https://urllib3.readthedocs.io/en/latest/)와 ν•¨κ»˜ μž‘λ™ν–ˆμŠ΅λ‹ˆλ‹€.

  • nltk (3.2.5)
  • urllib3 (1.22)
  • Mac OSX 10.12.16
  • Python 2.7.13 | Continuum Analytics, Inc. | (κΈ°λ³Έκ°’, 2016 λ…„ 12 μ›” 20 일, 23:05:08)
    [GCC 4.2.1 ν˜Έν™˜ Apple LLVM 6.0 (clang-600.0.57)] on darwin

λ‚΄κ°€ 말할 μˆ˜μžˆλŠ” ν•œ,이 λ¬Έμ œλŠ” macOS에 영ν–₯을 λ―ΈμΉ˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. μ§€κΈˆκΉŒμ§€ Python 3.6을 μ‚¬μš©ν•˜μ—¬

  • macOS 10.13 (μ‹€νŒ¨)
  • Centos 7.2 (성곡)
  • Ubuntu 16.04 (성곡)

python3에 λŒ€ν•œ μˆ˜μ • 된 OP 슀크립트 :

from multiprocessing import Process
import nltk
import time


def child_fn():
    from urllib.request import urlopen
    print("Fetch URL")
    print(urlopen("https://www.google.com").read()[:100])
    print("Done")


child_process = Process(target=child_fn)
child_process.start()
child_process.join()
print("Child process returned")
time.sleep(1)

μ‚°μΆœ:

Fetch URL
Child process returned

ν•˜μœ„ ν”„λ‘œμ„ΈμŠ€κ°€ 예기치 μ•Šκ²Œ μ’…λ£Œλ˜μ–΄μ΄ Stack Overflow κ²Œμ‹œλ¬Όμ— ν‘œμ‹œλœ 것과 μœ μ‚¬ν•œ 좜λ ₯을 μˆ˜μ‹ ν•©λ‹ˆλ‹€.

λ‚˜λŠ” 이것이 μƒλ‹Ήνžˆ 마음이 ν”λ“€λ¦¬λŠ” 것이라고 μƒκ°ν•©λ‹ˆλ‹€. MacOSμ—μ„œ μŠ€λ ˆλ“œ μ²˜λ¦¬μ™€ κ΄€λ ¨μ΄μžˆμ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

λ‚˜λŠ” nltk에 λŒ€ν•΄ 믿을 수 없을 μ •λ„λ‘œ μ΅μˆ™ν•˜μ§€ μ•Šμ§€λ§Œ ν…ŒμŠ€νŠΈκ°€ 톡과 / μ‹€νŒ¨ν•œ 원인을 ν™•μΈν•˜κΈ° μœ„ν•΄ μ•½κ°„ λˆˆμ„ λ©€κ²Œν–ˆλ‹€. ν…ŒμŠ€νŠΈλ₯Ό ν†΅κ³Όν•˜κΈ° μœ„ν•΄ __init__.py νŒ¨ν‚€μ§€μ— μˆ˜ν–‰ν•΄μ•Όν•˜λŠ” μž‘μ—…μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.


μ„ΈλΆ€ 정보 (ν™•μž₯ν•˜λ €λ©΄ 클릭)

###########################################################
# TOP-LEVEL MODULES
###########################################################

# Import top-level functionality into top-level namespace

from nltk.collocations import *
from nltk.decorators import decorator, memoize
# from nltk.featstruct import *
# from nltk.grammar import *
from nltk.probability import *
from nltk.text import *
# from nltk.tree import *
from nltk.util import *
from nltk.jsontags import *

# ###########################################################
# # PACKAGES
# ###########################################################

# from nltk.chunk import *
# from nltk.classify import *
# from nltk.inference import *
from nltk.metrics import *
# from nltk.parse import *
# from nltk.tag import *
from nltk.tokenize import *
from nltk.translate import *
# from nltk.sem import *
# from nltk.stem import *

# Packages which can be lazily imported
# (a) we don't import *
# (b) they're slow to import or have run-time dependencies
#     that can safely fail at run time

from nltk import lazyimport
app = lazyimport.LazyModule('nltk.app', locals(), globals())
chat = lazyimport.LazyModule('nltk.chat', locals(), globals())
corpus = lazyimport.LazyModule('nltk.corpus', locals(), globals())
draw = lazyimport.LazyModule('nltk.draw', locals(), globals())
toolbox = lazyimport.LazyModule('nltk.toolbox', locals(), globals())

# Optional loading

try:
    import numpy
except ImportError:
    pass
else:
    from nltk import cluster

# from nltk.downloader import download, download_shell
# try:
#     from six.moves import tkinter
# except ImportError:
#     pass
# else:
#     try:
#         from nltk.downloader import download_gui
#     except RuntimeError as e:
#         import warnings
#         warnings.warn("Corpus downloader GUI not loaded "
#                       "(RuntimeError during import: %s)" % str(e))

# explicitly import all top-level modules (ensuring
# they override the same names inadvertently imported
# from a subpackage)

# from nltk import ccg, chunk, classify, collocations
# from nltk import data, featstruct, grammar, help, inference, metrics
# from nltk import misc, parse, probability, sem, stem, wsd
# from nltk import tag, tbl, text, tokenize, translate, tree, treetransforms, util


ν₯λ―Έλ‘­κ²Œλ„ λͺ¨λ“  λΉ„ν™œμ„±ν™” 된 μˆ˜μž…μ€ ꢁ극적으둜 tkinter μˆ˜μž…μœΌλ‘œ λŒμ•„κ°€λŠ”λ° 이것이 κ·Όλ³Έ 원인 import nltk λ₯Ό import tkinter 둜 λ°”κΎΈλ©΄ tkinterλ₯Ό μ°Έμ‘°ν•˜λŠ” 맀우 μœ μ‚¬ν•œ 좩돌 λ³΄κ³ μ„œκ°€ ν‘œμ‹œλ©λ‹ˆλ‹€.

λ‚΄κ°€ μ•Œ 수 μžˆλ“―μ΄μ΄ νŒ¨ν‚€μ§€λŠ” tkinter 직접 κ°€μ Έμ˜΅λ‹ˆλ‹€.

  • nltk.app
  • nltk.draw
  • nltk.sem

μœ„μ˜ κΈ°λ³Έ νŒ¨ν‚€μ§€ __init__ λ³€κ²½ μ‚¬ν•­μ—μ„œ λ¬Έμ œκ°€μžˆλŠ” κ°€μ Έ μ˜€κΈ°μ™€ tkinter κ°€μ Έ 였기λ₯Ό μΆ”μ ν•˜λŠ” 방법

  • nltk.featstruct ( sem )
  • nltk.grammar ( featstruct )
  • nltk.tree ( grammar )
  • nltk.chunk ( chunk.named_entity > tree )
  • nltk.parse ( parse.bllip > tree )
  • nltk.tag ( tag.stanford > parse )
  • nltk.classify ( classify.senna > tag )
  • nltk.inference ( inference.discourse > sem , tag )
  • nltk.stem ( stem.snowball > corpus > corpus.reader.timit > tree )

κ°μ‚¬ν•©λ‹ˆλ‹€ @rpkilby , 그것은 맀우 λ„μ›€μ΄λ©λ‹ˆλ‹€!

이 문제처럼 λ³΄μž…λ‹ˆλ‹€ https://stackoverflow.com/questions/16745507/tkinter-how-to-use-threads-to-preventing-main-event-loop-from-freezing

λ‚˜λŠ” νŒ…ν¬ ν„°κ°€ κ½€ μ˜€λž«λ™μ•ˆ μš°λ¦¬μ—κ²Œ 고톡 포인트라고 μƒκ°ν•©λ‹ˆλ‹€. μ•„λ§ˆλ„ λŒ€μ•ˆμ„ 찾을 수 μžˆλ‹€λ©΄ 쒋을 κ²ƒμž…λ‹ˆλ‹€.

λ‚˜λŠ” λ™μ˜ν•œλ‹€. 단기적인 해결책은 tkinterκ°€ ν•„μš”ν•œ ν΄λž˜μŠ€μ™€ λ©”μ†Œλ“œ μ•ˆμ— tkinter κ°€μ Έ 였기λ₯Ό 묻고 ν•„μš”ν•˜μ§€ μ•Šμ€ ν”„λ‘œκ·Έλž¨μ—μ„œ κ°€μ Έ μ˜€λŠ” 것을 ν”Όν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. μš°λ¦¬λŠ” 이미 numpy에 λŒ€ν•΄ λΉ„μŠ·ν•œ μž‘μ—…μ„ μˆ˜ν–‰ν–ˆμŠ΅λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰