我安装了NLTK软件包,我可以在Jupyter Notebook中导入NLTK,但不能在PyCharm中导入它。
>>> import nltk
>>> import sys
>>> print('\n'.join(sys.path))
在jupyter笔记本中:
/Users/morphy/anaconda3/lib/python36.zip
/Users/morphy/anaconda3/lib/python3.6
/Users/morphy/anaconda3/lib/python3.6/lib-dynload
/Users/morphy/anaconda3/lib/python3.6/site-packages
/Users/morphy/anaconda3/lib/python3.6/site-packages/aeosa
/Users/morphy/anaconda3/lib/python3.6/site-packages/IPython/extensions
/Users/morphy/.ipython
但是在Pycharm:
/Users/morphy/Documents/workplace/practice
/Users/morphy/Documents/workplace/practice
/Users/morphy/anaconda3/lib/python36.zip
/Users/morphy/anaconda3/lib/python3.6
/Users/morphy/anaconda3/lib/python3.6/lib-dynload
/Users/morphy/anaconda3/lib/python3.6/site-packages
/Users/morphy/anaconda3/lib/python3.6/site-packages/aeosa
Traceback (most recent call last):
File "/Users/morphy/Documents/workplace/practice/text_classsfier_test.py", line 3, in <module>
import nltk
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/nltk/metrics/scores.py", line 18, in <module>
from scipy.stats.stats import betai
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/scipy/__init__.py", line 61, in <module>
from numpy import show_config as show_numpy_config
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/core/__init__.py", line 74, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/Users/morphy/anaconda3/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/Users/morphy/anaconda3/lib/python3.6/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/Users/morphy/anaconda3/lib/python3.6/unittest/case.py", line 5, in <module>
import difflib
File "/Users/morphy/Documents/workplace/practice/difflib.py", line 921
raise ValueError, 'unknown tag %r' % (tag,)
^
SyntaxError: invalid syntax
当我导入其他软件包如numpy和sklearn时,也会发生同样的错误。
答案 0 :(得分:0)
更新:已解决。
我在当前工作目录中创建了一个名为difflib.py的文件,因此当导入numpy时,它将调用此文件而不是它自己的库文件。
此问题与Numpy import throws AttributeError: 'module' object has no attribute 'core'
类似