Reputation: 6762
i have a private module, which for better or worse, i've called time
.
i have another module, which i've called graph
that resides in the same directory it uses the redis-py
module.
unfortunately, my time
module doesn't do exactly what the standard time
module does, and as a result i get the following error:
$ /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'
removing my time
module rectifies the error. is there a way i can hack up my graph.py
to basically ignore my time
module and use the system one? i've tried using from __future__ import absolute_import
but that didn't seem to make a difference.
Upvotes: 0
Views: 1153
Reputation: 1125058
It is not your graph
module that is importing time
; it is redis.client
that does.
Your time
is also a top-level module. Other Python code has no means to distinguish between your module and the standard library version.
You could alter the sys.path
order and make sure standard library modules are found first, but really you should just rename your module. It is easy enough to give it a different name.
Upvotes: 1