【问题标题】:Python: Impossible to import mktime in Eclipse: ImportErrorPython:在 Eclipse 中无法导入 mktime:ImportError
【发布时间】:2023-04-01 20:25:02
【问题描述】:

如果我只在命令行中导入 pgdb,它可以正常工作。

直到最近它在 Eclipse 中也可以正常工作(使用完全相同的 Python 2.7.2),但是现在,当我导入 pgdb 时,即使在一个非常简单的文件中(仅包含 import pgdb),我也会收到此错误消息:

Traceback (most recent call last):
  File ".../src/pgdbtest.py", line 8, in <module>
    import pgdb
  File "build/bdist.macosx-10.6-x86_64/egg/pgdb.py", line 66, in <module>
  File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 7, in <module>
  File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 4, in __bootstrap__
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 908, in resource_filename
    self, resource_name
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1383, in get_resource_filename
    self._extract_resource(manager, self._eager_to_zip(name))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1401, in _extract_resource
    timestamp = time.mktime(date_time)
AttributeError: 'module' object has no attribute 'mktime'

其实更一般的,我发现如果我尝试from time import mktime,我也有错误:

from time import mktime
ImportError: cannot import name mktime

【问题讨论】:

    标签:
    python
    eclipse
    import
    module
    pgdb