首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >site.py: AttributeError:在运行PyCharm中的任何python文件时,'ModuleType‘对象没有属性’ModuleType‘

site.py: AttributeError:在运行PyCharm中的任何python文件时,'ModuleType‘对象没有属性’ModuleType‘
EN

Stack Overflow用户
提问于 2016-04-16 21:19:33
回答 1查看 2.8K关注 0票数 3

我使用nltk在Python3.4上用PyCharm解析英语。当我运行我的文件时,我收到以下错误:

代码语言:javascript
运行
复制
Error processing line 1 of /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zope.interface-4.1.3-py3.4-nspkg.pth:

  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 167, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  AttributeError: 'module' object has no attribute 'ModuleType'

Remainder of file ignored
Traceback (most recent call last):
  File "/Users/james/naturallang/grammar.py", line 3, in <module>
    import nltk.book
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/__init__.py", line 89, in <module>
    from nltk.internals import config_java
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 424, in <module>
    _PopenSelector = selectors.SelectSelector
AttributeError: 'module' object has no attribute 'SelectSelector'

经过一些修改后,我发现运行一个空文件会导致以下错误:

代码语言:javascript
运行
复制
Error processing line 1 of /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zope.interface-4.1.3-py3.4-nspkg.pth:

  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 167, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  AttributeError: 'module' object has no attribute 'ModuleType'

Remainder of file ignored

调试空文件将使我:

代码语言:javascript
运行
复制
Error processing line 1 of /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zope.interface-4.1.3-py3.4-nspkg.pth:

  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 167, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  AttributeError: 'module' object has no attribute 'ModuleType'

Remainder of file ignored
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_imports.py", line 9, in <module>
    import xmlrpclib
ImportError: No module named 'xmlrpclib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_imports.py", line 11, in <module>
    import xmlrpc.client as xmlrpclib
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 135, in <module>
    import http.client
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 69, in <module>
    import email.parser
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/feedparser.py", line 27, in <module>
    from email import message
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/message.py", line 16, in <module>
    from email import utils
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/utils.py", line 28, in <module>
    import random
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/random.py", line 40, in <module>
    from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
ImportError: cannot import name 'MethodType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 10, in <module>
    import pydev_imports
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_imports.py", line 13, in <module>
    from _pydev_imps import _pydev_xmlrpclib as xmlrpclib
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_xmlrpclib.py", line 294
    True, False = True, False
       ^
SyntaxError: can't assign to keyword

我在OS上使用的是PyCharm 5.04专业版。我认为这与我的编辑器有关,但我不确定。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-17 22:39:42

当前目录中有一个名为types.py的文件。

这个文件隐藏了作为标准库一部分的types模块。nltk程序(非常)间接地试图导入types,获取缺少ModuleType属性的模块,从而导致ImportError,它永远不会被捕获并产生回溯。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36669895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档