sys.path在哪里被替换?

编程入门 行业动态 更新时间:2024-10-27 02:31:30
本文介绍了sys.path在哪里被替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

某些图书馆以我不想要的方式更改我的 sys.path 。

Some library does change my sys.path in a way that I don't want it to.

但是我找不到它。受影响的virtualenv安装了很多库。

But I can't find it. The affected virtualenv has a lot of libraries installed.

我用一个改变了修改的类替换了sys.path,但这并没有帮助,因为代码似乎更改 sys.path 如下所示:

I replaced sys.path with a own class which alters the modifications, but this does not help, since the code seems to alter sys.path like this:

sys.path= [...] + sys.path

我如何找到恶代码行及其堆栈跟踪?

How can I find the "evil" code line and its stack trace?

相关

  • 调试sys.path 的修改
  • Debugging modifications of sys.path
推荐答案

我发现这样的恶意代码行。

I found the evil code line like this.

我改变了sys.globals ['sys' ]在sitecustomize.py:

I alter sys.globals['sys'] in sitecustomize.py:

# 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 ,我看到代码行堆栈跟踪。

It raises AttributeIsReadonly and I see the code line and the stack trace.

更多推荐

sys.path在哪里被替换?

本文发布于:2023-11-23 21:17:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sys   path

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!