0

我有一个私有模块,无论好坏,我都调用了time. 我有另一个模块,我称之为graph驻留在它使用该redis-py模块的同一目录中。

不幸的是,我的time模块并不完全符合标准time模块的功能,因此我收到以下错误:

$ /opt/stuff/bin/python /opt/stuff/lib/utils/graph.py
Traceback (most recent call last):
  File "/opt/stuff/lib/utils/graph.py", line 6, in <module>
    import redis
  File "/opt/stuff/lib/python2.6/site-packages/redis/__init__.py", line 1, in <module>
    from redis.client import Redis, StrictRedis
  File "/opt/stuff/lib/python2.6/site-packages/redis/client.py", line 6, in <module>
    import time as mod_time
  File "/opt/stuff/lib/utils/time.py", line 5, in <module>
    import pytz
  File "/usr/lib/python2.6/site-packages/pytz/__init__.py", line 32, in <module>
    from pkg_resources import resource_stream
  File "/opt/stuff/lib/python2.6/site-packages/pkg_resources.py", line 761, in <module>
    class Environment(object):
  File "/opt/stuff/lib/python2.6/site-packages/pkg_resources.py", line 764, in Environment
    def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
  File "/opt/stuff/lib/python2.6/site-packages/pkg_resources.py", line 140, in get_supported_platform
    plat = get_build_platform(); m = macosVersionString.match(plat)
  File "/opt/stuff/lib/python2.6/site-packages/pkg_resources.py", line 282, in get_build_platform
    from distutils.util import get_platform
  File "/opt/stuff/lib64/python2.6/distutils/__init__.py", line 25, in <module>
    from distutils import dist, sysconfig
  File "/usr/lib64/python2.6/distutils/dist.py", line 21, in <module>
    from distutils.fancy_getopt import FancyGetopt, translate_longopt
  File "/usr/lib64/python2.6/distutils/fancy_getopt.py", line 32, in <module>
    longopt_xlate = string.maketrans('-', '_')
AttributeError: 'module' object has no attribute 'maketrans'

删除我的time模块可以纠正错误。有没有办法让我graph.py基本上忽略我的time模块并使用系统模块?我试过使用from __future__ import absolute_import,但这似乎没有什么不同。

4

1 回答 1

1

graph导入的不是您的模块time;就是redis.client这样。

time也是一个顶级模块。其他 Python 代码无法区分您的模块和标准库版本。

您可以更改sys.path顺序并确保首先找到标准库模块,但实际上您应该重命名您的模块。给它起一个不同的名字很容易。

于 2013-10-04T22:17:30.450 回答