Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

pycharm - how to fix ImportError: cannot import name 'format_exception_only' in python

I am using pycharm community version for python 3.6.1 as I'm beginner when i try to run simple tokenize program -

import nltk
from nltk.tokenize import word_tokenize
word_tokenize(" hellow world im nltk")

I get the following error -

C:UsersAmnaaAppDataLocalProgramsPythonPython36-32python.exe E:/test/token.py
Traceback (most recent call last):
  File "E:/test/token.py", line 1, in <module>
    import nltk
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsite-packages
ltk\__init__.py", line 89, in <module>
    from nltk.internals import config_java
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsite-packages
ltkinternals.py", line 11, in <module>
    import subprocess
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsubprocess.py", line 126, in <module>
    import threading
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32lib	hreading.py", line 7, in <module>
    from traceback import format_exc as _format_exc
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32lib	raceback.py", line 5, in <module>
    import linecache
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32liblinecache.py", line 11, in <module>
    import tokenize
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32lib	okenize.py", line 35, in <module>
    from token import *
  File "E:	est	oken.py", line 2, in <module>
    from nltk.tokenize import word_tokenize
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsite-packages
ltk	okenize\__init__.py", line 64, in <module>
    from nltk.tokenize.mwe      import MWETokenizer
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsite-packages
ltk	okenizemwe.py", line 31, in <module>
    from nltk.util import Trie
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libsite-packages
ltkutil.py", line 13, in <module>
    import pydoc
  File "C:UsersAmnaaAppDataLocalProgramsPythonPython36-32libpydoc.py", line 72, in <module>
    from traceback import format_exception_only
ImportError: cannot import name 'format_exception_only'

Process finished with exit code 1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

File "E: est oken.py", line 2, in from nltk.tokenize import word_tokenize

There happen to be another script with the same name Python is looking for. Python got confused about the script from package and your own script because it start searching from the folder where you are. So just change your own script to another name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...