2

我使用的版本是python2.7,使用脚本时出现错误,但在命令行中可以使用。

from twisted.internet import protocol, reactor  

和错误:

ravjqpejcnngpig.eqo/re/fgh/ocr
Traceback (most recent call last):
  File "./tsTclntTW.py", line 5, in <module>
    from twisted.internet import protocol, reactor
  File "/usr/local/lib/python2.7/dist-packages/twisted/__init__.py", line 18, in <module>
    from zope.interface import Interface
  File "/usr/local/lib/python2.7/dist-packages/zope.interface-4.0.1-py2.7-linux-x86_64.egg/zope/__init__.py", line 3, in <module>
    import pkg_resources
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 698, in <module>
    self.callbacks.append(callback)
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 701, in Environment

  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 96, in get_supported_platform
    distutils.util.get_platform() normally reports the minimum version
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 222, in get_build_platform
    # fallback for MacPorts
  File "/usr/lib/python2.7/distutils/util.py", line 65, in get_platform
    osname = string.lower(osname)
AttributeError: 'module' object has no attribute 'lower'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
    from apport.report import Report
  File "/usr/lib/python2.7/dist-packages/apport/report.py", line 18, in <module>
    import problem_report
  File "/usr/lib/python2.7/dist-packages/problem_report.py", line 16, in <module>
    from email.mime.multipart import MIMEMultipart
  File "/usr/lib/python2.7/email/mime/multipart.py", line 9, in <module>
    from email.mime.base import MIMEBase
  File "/usr/lib/python2.7/email/mime/base.py", line 9, in <module>
    from email import message
  File "/usr/lib/python2.7/email/message.py", line 16, in <module>
    import email.charset
  File "/usr/lib/python2.7/email/charset.py", line 14, in <module>
    import email.quoprimime
  File "/usr/lib/python2.7/email/quoprimime.py", line 48, in <module>
    from string import hexdigits
ImportError: cannot import name hexdigits

Original exception was:
Traceback (most recent call last):
  File "./tsTclntTW.py", line 5, in <module>
    from twisted.internet import protocol, reactor
  File "/usr/local/lib/python2.7/dist-packages/twisted/__init__.py", line 18, in <module>
    from zope.interface import Interface
  File "/usr/local/lib/python2.7/dist-packages/zope.interface-4.0.1-py2.7-linux-x86_64.egg/zope/__init__.py", line 3, in <module>
    import pkg_resources
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 698, in <module>
    self.callbacks.append(callback)
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 701, in Environment

  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 96, in get_supported_platform
    distutils.util.get_platform() normally reports the minimum version
  File "/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 222, in get_build_platform
    # fallback for MacPorts
  File "/usr/lib/python2.7/distutils/util.py", line 65, in get_platform
    osname = string.lower(osname)
AttributeError: 'module' object has no attribute 'lower'

我已经重新安装了我使用的 Python,但它不起作用,我在 Ubuntu 12.04 中。我也有

grep ravjqpejcnngpig.eqo/re/fgh/ocr . -R -n

/usr/lib/python2.7但没有返回。

4

1 回答 1

4

也许你string的项目中有一个命名的模块,它隐藏了同名的库模块。


编辑:要找出答案,请将其添加到您的脚本中,就在失败的导入语句之前:

import string
print string.__file__
于 2012-09-11T07:21:26.970 回答