I was trying to use nltk for python and then confronted with this problem.
>>>from nltk.corpus import sinica_tree
and then the error occured:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name sinica_tree
I've checked that nltk is installed and that sinica_tree is also installed using nltk.download(). Need some help for this.
According to the documentation it looks like it should be:
from nltk.corpus import sinica_treebank
See: http://www.nltk.org/nltk_data/
>>>import nltk
>>>nltk.download()
---------------------------------------------------------------------------
d) Download l) List u) Update c) Config h) Help q) Quit
---------------------------------------------------------------------------
Downloader> d
Download which package (l=list; x=cancel)?
Identifier> treebank
then try to import
from nltk.corpus import sinica_treebank
Related
I have been trying to import the Natural Language Toolkit (NLTK) as per the code provided on https://www.nltk.org/install.html.
This code works on the terminal window on my mac (10.14), but refuses to import NLTK onto the interpreter provided with Python (IDLE).
I have already tried changing the directory by importing os module. (Changed the directory to the default Python library on macOS). This in turn yields errors from the NLTK scripts itself.
This is the code I ran
>>> import os
>>> os.getcwd()
>>> os.chdir('/Library/Python/2.7/site-packages')
>>> import nltk
I expected the nltk to successfully import after changing the directory.
However, it shows errors in the NLTK scripts itself (I'm assuming) which are as follows:
"Traceback (most recent call last):
File "", line 1, in
import nltk
File "/Library/Python/2.7/site-packages/nltk/init.py", line 99,
in
from nltk.internals import config_java
File "/Library/Python/2.7/site-packages/nltk/internals.py", line 28,
in
from six import string_types
ModuleNotFoundError: No module named 'six'"
I was trying to use PunktWordTokenizer and it was occurred an error as below.
from nltk.tokenize.punkt import PunktWordTokenizer
And this gave the following error message.
Traceback (most recent call last): File "file", line 5, in <module>
from nltk.tokenize.punkt import PunktWordTokenizer ImportError: cannot import name PunktWordTokenizer
I've checked that nltk is installed and that PunkWordTokenzer is also installed using nltk.download(). Need some help for this.
PunktWordTokenizer was previously exposed to user but not any more. You can rather use WordPunctTokenizer.
from nltk.tokenize import WordPunctTokenizer
WordPunctTokenizer().tokenize(“text to tokenize”)
The difference is :
PunktWordTokenizer splits on punctuation, but keeps it with the word. Where as WordPunctTokenizer splits all punctuations into separate tokens.
For example, given Input: This’s a test
PunktWordTokenizer: [‘This’, “‘s”, ‘a’, ‘test’]
WordPunctTokenizer: [‘This’, “‘”, ‘s’, ‘a’, ‘test’]
There appears to be a regression related to PunktWordTokenizer in 3.0.2. The issue was not present in 3.0.1, rolling back to that version or earlier fixes the issue.
>>> import nltk
>>> nltk.__version__
'3.0.2'
>>> from nltk.tokenize import PunktWordTokenizer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name PunktWordTokenizer
For solving this Try pip install -U nltk to upgrade your NLTK version.
Using windows 10
I've install textblob using "py -m pip install textblob".
I can import textblob, or from textblob import blob,word
But i cant: from textblobl import Textblob.
The error i get is:
Traceback (most recent call last):
File "", line 1, in
from textblob import Textblob
ImportError: cannot import name 'Textblob'
Thanks.
You can try whit this:
from textblob import TextBlob
you can try change your file name TextBlob.py
I'm using sublime text 2 to run python 2.7. I have downloaded and installed mathplotlib. When I type the code:
import matplotlib.pyplot
I'm getting this error.
Traceback (most recent call last):
File "/Volumes/HP v190b/Python - Squash Coursework/squashFINAL.py", line 212, in <module>
import matplot.pyplot as plt
ImportError: No module named matplot.pyplot
Any ideas why? I'm using a Mac!
You may check the dependencies, sometimes you need to install some dependencies so that you can import certain module, take a look at this link http://matplotlib.org/users/installing.html
I have to use framenet in nltk.corpus. So, I downloaded that corpus by using the nltk.download(). And the framenet directory is now C:\nltk_data\corpora\framenet_v15...
But when I import that framenet, I can't. I can't find the reason.
I want to some works as explained in here; http://nltk.org/howto/framenet.html
>>> import nltk.corpus.framenet
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk.corpus.framenet
ImportError: No module named framenet
Please, help me. Thanks.
In your link it import as so:
from nltk.corpus import framenet
Have you tried that?
EDIT: Version 3.0 and above of NLTK has framenet in the nltk.corpus.reader package, so it should be:
from nltk.corpus.reader import framenet