如何编辑CPython的Lib/importlib/_bootstrap.py? [英] How to edit CPython's Lib/importlib/_bootstrap.py?

查看:79
本文介绍了如何编辑CPython的Lib/importlib/_bootstrap.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CPython的Lib/importlib/_bootstrap.py文件,但是当我导入模块时,在MacOS上当前的CPython安装(与Homebrew软件包管理器一起安装)中所做的编辑无效.

I would like to play with CPython's Lib/importlib/_bootstrap.py file, but my edits in my current CPython installation on MacOS (installed with the Homebrew package manager) have no effect when I import a module.

例如,如果我在 _init_module_attrs 函数主体的开头添加 print("hello",file = sys.stderr)语句:

For instance if I add the print("hello", file=sys.stderr) statement at the beginning of the body of the _init_module_attrs function:

$ vi /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py

然后导入一个模块:

$ python3 -c "import pathlib"

什么都没打印.

推荐答案

importlib._bootstrap 是冻结的模块.要对其进行更新,应重新编译 importlib 模块:

importlib._bootstrap is a frozen module. To update it, the importlib module should be recompiled:

$ cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/Python/
$ make regen-importlib
$ make

这篇关于如何编辑CPython的Lib/importlib/_bootstrap.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆