有些库确实以我不希望它改变的方式改变了我的sys.path。
但我找不到。受影响的virtualenv安装了许多库。
我用自己的类替换了sys.path,它改变了修改,但是这没有帮助,因为代码似乎像这样改变了sys.path:
sys.path= [...] + sys.path如何找到“邪恶”代码行及其堆栈跟踪?
相关
发布于 2015-10-19 10:47:28
我发现了像这样的邪恶代码行。
我在sitecustomize.py中更改sys.globals‘’sys‘:
# sitecustomize.py
import sys
class AttributeIsReadonly(ValueError):
pass
class MakeModuleAttributesReadonly(object):
def __init__(self, module, readonly_attributes):
self.module=module
self.readonly_attributes=readonly_attributes
def __setattr__(self, item, value):
if item in ['module', 'readonly_attributes']:
return super(MakeModuleAttributesReadonly, self).__setattr__(item, value)
if item in self.readonly_attributes:
raise AttributeIsReadonly('Access on attribute %r is readonly' % item)
return setattr(self.module, item, value)
def __getattr__(self, item):
return getattr(self.module, item)
sys.modules['sys']=MakeModuleAttributesReadonly(sys, ['path'])
#import sys
#sys.path=sys.path # this will raise the above AttributeIsReadonly它引发AttributeIsReadonly,我看到代码行和堆栈跟踪。
https://stackoverflow.com/questions/33212466
复制相似问题