Python扩展模块可以看作是一个用C或C++编写的动态链接库(DLL)或共享对象(SO),它实现了一些Python对象和函数,这些对象和函数可以在Python程序中像其他Python对象和函数一样使用。本文的意图是在深入地、系统低学习相关编程规范之前,先通过一个小示例建立感性的体会。
Python/C API Reference Manual:
中文版:
docs.python.org/zh-cn/3/c-api/index.html
英文版:
https://docs.python.org/3/c-api/index.html
知道大家汉语不一定流利,所以附了英文版。
中文版:
https://blog.csdn.net/eloudy/article/details/148689871?spm=1001.2014.3001.5502
英文版:
https://docs.python.org/3/extending/extending.html#a-simple-example
如果精通 C 语言编程,那么向 Python 添加新的内置模块是相当容易的。这类扩展模块可以完成两件直接用 Python 无法做到的事情:实现新的内置对象类型,以及调用 C 库函数和系统调用。本文给一个简单示例,调用了 libc 库函数中的两个数学函数:sin,cos。
为了支持扩展,Python API(应用程序编程接口)定义了一组函数、宏和变量,这些接口提供了对 Python 运行时系统大部分功能的访问。在 C 源文件中包含头文件 "Python.h" 即可使用 Python API。
0. 示例要做到的效果
创建一个python module,名字为 trigono,表示三角函数 模块之意,其中包含两个自定义的三角函数。实现效果:
0.1. 一个可以导入的 c语言编写的 module:trigono,可以import;
0.2. 使用 trigono 的方法 sine( float r) 计算 r 弧度的正弦值;
0.3. 使用 trigono 的方法 cosine(float r) 计算 r 弧度的余弦值;
1,python 的 C 语言三角函数模块示例
Python/C API Reference Manual
基于python API 定义的两个正余弦计算函数,sineext() 和 cosineext()。之所以取这样的 c 语言函数名是为了区分其对应的 python 函数名称 sine和 cosine。以体现其中的机制l。
这个小代码适合多盯一会儿,感受到每个部分的大概含义。
总共包含两个文件 trigonometric.c 和 setup.py:
trigonometric.c
#include <Python.h>
#include <math.h>
static PyObject* sineext(PyObject* self, PyObject* args)
{
float input;
if(!PyArg_ParseTuple(args, "f", &input)){
return NULL;
}
return Py_BuildValue("f", sin(input));
}
static PyObject* cosineext(PyObject* self, PyObject* args)
{
float input;
if(!PyArg_ParseTuple(args, "f", &input)){
return NULL;
}
return Py_BuildValue("f", cos(input));
}
static PyMethodDef TrigonoMethods[]={
{"sinee", sineext, METH_VARARGS, "Sine of the input radian."},
{"cosinee", cosineext, METH_VARARGS, "Cosine of the input radian."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef trigonometricmodule = {
PyModuleDef_HEAD_INIT,
"trigono",
"A module that provides a 'double' function.",
-1,
TrigonoMethods
};
PyMODINIT_FUNC PyInit_trigono(void)
{
return PyModule_Create(&trigonometricmodule);
}
setup.py
from distutils.core import setup, Extension
module1 = Extension('trigono', sources = ['trigonometric.c'])
setup (name = 'PackageName',
version = '1.0',
description = 'This is a package for trigonometric function extension',
ext_modules = [module1])
构建模块:
python3 setup.py build
2,python C 扩展 API 解释
以下是关键 API 和结构体的介绍:
核心结构体
PyMethodDef
定义模块中的方法列表
结构体成员:
struct PyMethodDef {
const char *ml_name; // 方法名
PyCFunction ml_meth; // C 函数指针
int ml_flags; // 调用约定标志
const char *ml_doc; // 方法文档字符串
};
示例中用于定义 TrigonoMethods 数组
PyModuleDef
定义模块的元信息
结构体成员:
struct PyModuleDef {
PyModuleDef_Base m_base; // 基类
const char *m_name; // 模块名
const char *m_doc; // 模块文档
Py_ssize_t m_size; // 模块状态大小
PyMethodDef *m_methods; // 方法表
// ... 其他可选成员
};
示例中用于定义 trigonometricmodule
关键 API 函数
PyArg_ParseTuple
解析 Python 传入的参数
格式字符串:"f" 表示解析一个 float 类型参数;其他常见格式:"i"(int), "d"(double), "s"(字符串)等;
Py_BuildValue
构建 Python 对象返回给调用者
格式字符串与 PyArg_ParseTuple 类似, 示例中返回浮点数 ("f")
PyModule_Create
创建新的模块对象
参数是 PyModuleDef 结构体指针
PyMODINIT_FUNC
模块初始化函数的返回类型宏
实际展开为 PyObject* 并添加必要的修饰符
函数签名约定
模块函数签名
static PyObject* func_name(PyObject *self, PyObject *args)
self: 对于模块函数是 NULL,对于类方法是实例对象
args: 包含所有参数的元组
模块初始化函数
PyMODINIT_FUNC PyInit_module_name(void)
必须命名为 PyInit_ 加模块名
返回新创建的模块对象
3,构建打印
构建过程中输出的信息如下,有必要时可以用来分析这个构建过程的实现:
hipper@hipper-G21:~/ex_python$ python -v setup.py build
import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'posix' # <class '_frozen_importlib.BuiltinImporter'>
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
# installing zipimport hook
import 'time' # <class '_frozen_importlib.BuiltinImporter'>
import 'zipimport' # <class '_frozen_importlib.FrozenImporter'>
# installed zipimport hook
# /usr/lib/python3.10/encodings/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/encodings/__init__.py
# code object from '/usr/lib/python3.10/encodings/__pycache__/__init__.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/codecs.cpython-310.pyc matches /usr/lib/python3.10/codecs.py
# code object from '/usr/lib/python3.10/__pycache__/codecs.cpython-310.pyc'
import '_codecs' # <class '_frozen_importlib.BuiltinImporter'>
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d75d3760>
# /usr/lib/python3.10/encodings/__pycache__/aliases.cpython-310.pyc matches /usr/lib/python3.10/encodings/aliases.py
# code object from '/usr/lib/python3.10/encodings/__pycache__/aliases.cpython-310.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7120d30>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d75d3520>
# /usr/lib/python3.10/encodings/__pycache__/utf_8.cpython-310.pyc matches /usr/lib/python3.10/encodings/utf_8.py
# code object from '/usr/lib/python3.10/encodings/__pycache__/utf_8.cpython-310.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d75d34c0>
import '_signal' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/io.cpython-310.pyc matches /usr/lib/python3.10/io.py
# code object from '/usr/lib/python3.10/__pycache__/io.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/abc.cpython-310.pyc matches /usr/lib/python3.10/abc.py
# code object from '/usr/lib/python3.10/__pycache__/abc.cpython-310.pyc'
import '_abc' # <class '_frozen_importlib.BuiltinImporter'>
import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7121090>
import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7120e80>
# /usr/lib/python3.10/__pycache__/site.cpython-310.pyc matches /usr/lib/python3.10/site.py
# code object from '/usr/lib/python3.10/__pycache__/site.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/os.cpython-310.pyc matches /usr/lib/python3.10/os.py
# code object from '/usr/lib/python3.10/__pycache__/os.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/stat.cpython-310.pyc matches /usr/lib/python3.10/stat.py
# code object from '/usr/lib/python3.10/__pycache__/stat.cpython-310.pyc'
import '_stat' # <class '_frozen_importlib.BuiltinImporter'>
import 'stat' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71232b0>
# /usr/lib/python3.10/__pycache__/_collections_abc.cpython-310.pyc matches /usr/lib/python3.10/_collections_abc.py
# code object from '/usr/lib/python3.10/__pycache__/_collections_abc.cpython-310.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7123610>
# /usr/lib/python3.10/__pycache__/posixpath.cpython-310.pyc matches /usr/lib/python3.10/posixpath.py
# code object from '/usr/lib/python3.10/__pycache__/posixpath.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/genericpath.cpython-310.pyc matches /usr/lib/python3.10/genericpath.py
# code object from '/usr/lib/python3.10/__pycache__/genericpath.cpython-310.pyc'
import 'genericpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7161e40>
import 'posixpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71236a0>
import 'os' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7121ed0>
# /usr/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc matches /usr/lib/python3.10/_sitebuiltins.py
# code object from '/usr/lib/python3.10/__pycache__/_sitebuiltins.cpython-310.pyc'
import '_sitebuiltins' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7122fb0>
Processing user site-packages
Adding directory: '/home/hipper/.local/lib/python3.10/site-packages'
Processing .pth file: '/home/hipper/.local/lib/python3.10/site-packages/protobuf-3.20.2-py3.10-nspkg.pth'
# /usr/lib/python3.10/__pycache__/types.cpython-310.pyc matches /usr/lib/python3.10/types.py
# code object from '/usr/lib/python3.10/__pycache__/types.cpython-310.pyc'
import 'types' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7163dc0>
# /usr/lib/python3.10/importlib/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/importlib/__init__.py
# code object from '/usr/lib/python3.10/importlib/__pycache__/__init__.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/warnings.cpython-310.pyc matches /usr/lib/python3.10/warnings.py
# code object from '/usr/lib/python3.10/__pycache__/warnings.cpython-310.pyc'
import 'warnings' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7163190>
import 'importlib' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7163730>
# /usr/lib/python3.10/importlib/__pycache__/util.cpython-310.pyc matches /usr/lib/python3.10/importlib/util.py
# code object from '/usr/lib/python3.10/importlib/__pycache__/util.cpython-310.pyc'
# /usr/lib/python3.10/importlib/__pycache__/_abc.cpython-310.pyc matches /usr/lib/python3.10/importlib/_abc.py
# code object from '/usr/lib/python3.10/importlib/__pycache__/_abc.cpython-310.pyc'
import 'importlib._abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71622c0>
# /usr/lib/python3.10/__pycache__/contextlib.cpython-310.pyc matches /usr/lib/python3.10/contextlib.py
# code object from '/usr/lib/python3.10/__pycache__/contextlib.cpython-310.pyc'
# /usr/lib/python3.10/collections/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/collections/__init__.py
# code object from '/usr/lib/python3.10/collections/__pycache__/__init__.cpython-310.pyc'
import 'itertools' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/keyword.cpython-310.pyc matches /usr/lib/python3.10/keyword.py
# code object from '/usr/lib/python3.10/__pycache__/keyword.cpython-310.pyc'
import 'keyword' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718fe50>
# /usr/lib/python3.10/__pycache__/operator.cpython-310.pyc matches /usr/lib/python3.10/operator.py
# code object from '/usr/lib/python3.10/__pycache__/operator.cpython-310.pyc'
import '_operator' # <class '_frozen_importlib.BuiltinImporter'>
import 'operator' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718ff10>
# /usr/lib/python3.10/__pycache__/reprlib.cpython-310.pyc matches /usr/lib/python3.10/reprlib.py
# code object from '/usr/lib/python3.10/__pycache__/reprlib.cpython-310.pyc'
import 'reprlib' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718feb0>
import '_collections' # <class '_frozen_importlib.BuiltinImporter'>
import 'collections' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718ca00>
# /usr/lib/python3.10/__pycache__/functools.cpython-310.pyc matches /usr/lib/python3.10/functools.py
# code object from '/usr/lib/python3.10/__pycache__/functools.cpython-310.pyc'
import '_functools' # <class '_frozen_importlib.BuiltinImporter'>
import 'functools' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71d0ee0>
import 'contextlib' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718dc00>
import 'importlib.util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7162e00>
# /usr/lib/python3.10/importlib/__pycache__/machinery.cpython-310.pyc matches /usr/lib/python3.10/importlib/machinery.py
# code object from '/usr/lib/python3.10/importlib/__pycache__/machinery.cpython-310.pyc'
import 'importlib.machinery' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718d3c0>
# possible namespace for /home/hipper/.local/lib/python3.10/site-packages/google
Processing global site-packages
Adding directory: '/usr/local/lib/python3.10/dist-packages'
Processing .pth file: '/usr/local/lib/python3.10/dist-packages/easy-install.pth'
Adding directory: '/usr/lib/python3/dist-packages'
Processing .pth file: '/usr/lib/python3/dist-packages/MIGraphX.pth'
# /usr/lib/python3.10/__pycache__/sitecustomize.cpython-310.pyc matches /usr/lib/python3.10/sitecustomize.py
# code object from '/usr/lib/python3.10/__pycache__/sitecustomize.cpython-310.pyc'
# zipimport: found 17 names in '/usr/local/lib/python3.10/dist-packages/turingas-0.1-py3.10.egg'
# /usr/lib/python3/dist-packages/__pycache__/apport_python_hook.cpython-310.pyc matches /usr/lib/python3/dist-packages/apport_python_hook.py
# code object from '/usr/lib/python3/dist-packages/__pycache__/apport_python_hook.cpython-310.pyc'
import 'apport_python_hook' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718c4f0>
import 'sitecustomize' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71633a0>
import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71218a0>
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
# /usr/lib/python3.10/distutils/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/distutils/__init__.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/__init__.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/linecache.cpython-310.pyc matches /usr/lib/python3.10/linecache.py
# code object from '/usr/lib/python3.10/__pycache__/linecache.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/tokenize.cpython-310.pyc matches /usr/lib/python3.10/tokenize.py
# code object from '/usr/lib/python3.10/__pycache__/tokenize.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/re.cpython-310.pyc matches /usr/lib/python3.10/re.py
# code object from '/usr/lib/python3.10/__pycache__/re.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/enum.cpython-310.pyc matches /usr/lib/python3.10/enum.py
# code object from '/usr/lib/python3.10/__pycache__/enum.cpython-310.pyc'
import 'enum' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71d2f80>
# /usr/lib/python3.10/__pycache__/sre_compile.cpython-310.pyc matches /usr/lib/python3.10/sre_compile.py
# code object from '/usr/lib/python3.10/__pycache__/sre_compile.cpython-310.pyc'
import '_sre' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/sre_parse.cpython-310.pyc matches /usr/lib/python3.10/sre_parse.py
# code object from '/usr/lib/python3.10/__pycache__/sre_parse.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/sre_constants.cpython-310.pyc matches /usr/lib/python3.10/sre_constants.py
# code object from '/usr/lib/python3.10/__pycache__/sre_constants.cpython-310.pyc'
import 'sre_constants' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6739630>
import 'sre_parse' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6738e20>
import 'sre_compile' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6738550>
import '_locale' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/copyreg.cpython-310.pyc matches /usr/lib/python3.10/copyreg.py
# code object from '/usr/lib/python3.10/__pycache__/copyreg.cpython-310.pyc'
import 'copyreg' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d673b130>
import 're' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71d0670>
# /usr/lib/python3.10/__pycache__/token.cpython-310.pyc matches /usr/lib/python3.10/token.py
# code object from '/usr/lib/python3.10/__pycache__/token.cpython-310.pyc'
import 'token' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d673b3a0>
import 'tokenize' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d71d21d0>
import 'linecache' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d7163370>
/home/hipper/ex_python/setup.py:2: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.core import setup, Extension
import 'distutils' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718de40>
# /usr/lib/python3.10/distutils/__pycache__/core.cpython-310.pyc matches /usr/lib/python3.10/distutils/core.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/core.cpython-310.pyc'
# /usr/lib/python3.10/distutils/__pycache__/debug.cpython-310.pyc matches /usr/lib/python3.10/distutils/debug.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/debug.cpython-310.pyc'
import 'distutils.debug' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d673bb50>
# /usr/lib/python3.10/distutils/__pycache__/errors.cpython-310.pyc matches /usr/lib/python3.10/distutils/errors.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/errors.cpython-310.pyc'
import 'distutils.errors' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d673bac0>
# /usr/lib/python3.10/distutils/__pycache__/dist.cpython-310.pyc matches /usr/lib/python3.10/distutils/dist.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/dist.cpython-310.pyc'
# /usr/lib/python3.10/email/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/email/__init__.py
# code object from '/usr/lib/python3.10/email/__pycache__/__init__.cpython-310.pyc'
import 'email' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677cbb0>
# /usr/lib/python3.10/distutils/__pycache__/fancy_getopt.cpython-310.pyc matches /usr/lib/python3.10/distutils/fancy_getopt.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/fancy_getopt.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/string.cpython-310.pyc matches /usr/lib/python3.10/string.py
# code object from '/usr/lib/python3.10/__pycache__/string.cpython-310.pyc'
import '_string' # <class '_frozen_importlib.BuiltinImporter'>
import 'string' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677d360>
# /usr/lib/python3.10/__pycache__/getopt.cpython-310.pyc matches /usr/lib/python3.10/getopt.py
# code object from '/usr/lib/python3.10/__pycache__/getopt.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/gettext.cpython-310.pyc matches /usr/lib/python3.10/gettext.py
# code object from '/usr/lib/python3.10/__pycache__/gettext.cpython-310.pyc'
import 'gettext' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677de40>
import 'getopt' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677d990>
import 'distutils.fancy_getopt' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677cd00>
# /usr/lib/python3.10/distutils/__pycache__/util.cpython-310.pyc matches /usr/lib/python3.10/distutils/util.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/util.cpython-310.pyc'
# /usr/lib/python3.10/distutils/__pycache__/dep_util.cpython-310.pyc matches /usr/lib/python3.10/distutils/dep_util.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/dep_util.cpython-310.pyc'
import 'distutils.dep_util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677ed40>
# /usr/lib/python3.10/distutils/__pycache__/spawn.cpython-310.pyc matches /usr/lib/python3.10/distutils/spawn.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/spawn.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/subprocess.cpython-310.pyc matches /usr/lib/python3.10/subprocess.py
# code object from '/usr/lib/python3.10/__pycache__/subprocess.cpython-310.pyc'
import 'errno' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/signal.cpython-310.pyc matches /usr/lib/python3.10/signal.py
# code object from '/usr/lib/python3.10/__pycache__/signal.cpython-310.pyc'
import 'signal' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677ffd0>
# /usr/lib/python3.10/__pycache__/threading.cpython-310.pyc matches /usr/lib/python3.10/threading.py
# code object from '/usr/lib/python3.10/__pycache__/threading.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/_weakrefset.cpython-310.pyc matches /usr/lib/python3.10/_weakrefset.py
# code object from '/usr/lib/python3.10/__pycache__/_weakrefset.cpython-310.pyc'
import '_weakrefset' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d67be230>
import 'threading' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d67bc490>
import 'fcntl' # <class '_frozen_importlib.BuiltinImporter'>
import '_posixsubprocess' # <class '_frozen_importlib.BuiltinImporter'>
import 'select' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/selectors.cpython-310.pyc matches /usr/lib/python3.10/selectors.py
# code object from '/usr/lib/python3.10/__pycache__/selectors.cpython-310.pyc'
# /usr/lib/python3.10/collections/__pycache__/abc.cpython-310.pyc matches /usr/lib/python3.10/collections/abc.py
# code object from '/usr/lib/python3.10/collections/__pycache__/abc.cpython-310.pyc'
import 'collections.abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d67bf6a0>
import 'math' # <class '_frozen_importlib.BuiltinImporter'>
import 'selectors' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d67beda0>
import 'subprocess' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677f0a0>
# /usr/lib/python3.10/distutils/__pycache__/log.cpython-310.pyc matches /usr/lib/python3.10/distutils/log.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/log.cpython-310.pyc'
import 'distutils.log' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677f520>
import 'distutils.spawn' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677ee90>
import 'distutils.util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677d180>
import 'distutils.dist' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d673be50>
# /usr/lib/python3.10/distutils/__pycache__/cmd.cpython-310.pyc matches /usr/lib/python3.10/distutils/cmd.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/cmd.cpython-310.pyc'
# /usr/lib/python3.10/distutils/__pycache__/dir_util.cpython-310.pyc matches /usr/lib/python3.10/distutils/dir_util.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/dir_util.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/sysconfig.cpython-310.pyc matches /usr/lib/python3.10/sysconfig.py
# code object from '/usr/lib/python3.10/__pycache__/sysconfig.cpython-310.pyc'
import 'sysconfig' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66084f0>
import 'distutils.dir_util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6608280>
# /usr/lib/python3.10/distutils/__pycache__/file_util.cpython-310.pyc matches /usr/lib/python3.10/distutils/file_util.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/file_util.cpython-310.pyc'
import 'distutils.file_util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6608d30>
# /usr/lib/python3.10/distutils/__pycache__/archive_util.cpython-310.pyc matches /usr/lib/python3.10/distutils/archive_util.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/archive_util.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/zipfile.cpython-310.pyc matches /usr/lib/python3.10/zipfile.py
# code object from '/usr/lib/python3.10/__pycache__/zipfile.cpython-310.pyc'
import 'binascii' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/shutil.cpython-310.pyc matches /usr/lib/python3.10/shutil.py
# code object from '/usr/lib/python3.10/__pycache__/shutil.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/fnmatch.cpython-310.pyc matches /usr/lib/python3.10/fnmatch.py
# code object from '/usr/lib/python3.10/__pycache__/fnmatch.cpython-310.pyc'
import 'fnmatch' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d660bb20>
import 'zlib' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib/python3.10/__pycache__/bz2.cpython-310.pyc matches /usr/lib/python3.10/bz2.py
# code object from '/usr/lib/python3.10/__pycache__/bz2.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/_compression.cpython-310.pyc matches /usr/lib/python3.10/_compression.py
# code object from '/usr/lib/python3.10/__pycache__/_compression.cpython-310.pyc'
import '_compression' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66586d0>
# extension module '_bz2' loaded from '/usr/lib/python3.10/lib-dynload/_bz2.cpython-310-x86_64-linux-gnu.so'
# extension module '_bz2' executed from '/usr/lib/python3.10/lib-dynload/_bz2.cpython-310-x86_64-linux-gnu.so'
import '_bz2' # <_frozen_importlib_external.ExtensionFileLoader object at 0x7709d6658be0>
import 'bz2' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d660be80>
# /usr/lib/python3.10/__pycache__/lzma.cpython-310.pyc matches /usr/lib/python3.10/lzma.py
# code object from '/usr/lib/python3.10/__pycache__/lzma.cpython-310.pyc'
# extension module '_lzma' loaded from '/usr/lib/python3.10/lib-dynload/_lzma.cpython-310-x86_64-linux-gnu.so'
# extension module '_lzma' executed from '/usr/lib/python3.10/lib-dynload/_lzma.cpython-310-x86_64-linux-gnu.so'
import '_lzma' # <_frozen_importlib_external.ExtensionFileLoader object at 0x7709d66592d0>
import 'lzma' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6658c70>
import 'shutil' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d660ad70>
# /usr/lib/python3.10/__pycache__/struct.cpython-310.pyc matches /usr/lib/python3.10/struct.py
# code object from '/usr/lib/python3.10/__pycache__/struct.cpython-310.pyc'
import '_struct' # <class '_frozen_importlib.BuiltinImporter'>
import 'struct' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6659d20>
# /usr/lib/python3.10/__pycache__/pathlib.cpython-310.pyc matches /usr/lib/python3.10/pathlib.py
# code object from '/usr/lib/python3.10/__pycache__/pathlib.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/ntpath.cpython-310.pyc matches /usr/lib/python3.10/ntpath.py
# code object from '/usr/lib/python3.10/__pycache__/ntpath.cpython-310.pyc'
import 'ntpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d665b5e0>
# /usr/lib/python3.10/urllib/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/urllib/__init__.py
# code object from '/usr/lib/python3.10/urllib/__pycache__/__init__.cpython-310.pyc'
import 'urllib' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d665bfd0>
# /usr/lib/python3.10/urllib/__pycache__/parse.cpython-310.pyc matches /usr/lib/python3.10/urllib/parse.py
# code object from '/usr/lib/python3.10/urllib/__pycache__/parse.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/ipaddress.cpython-310.pyc matches /usr/lib/python3.10/ipaddress.py
# code object from '/usr/lib/python3.10/__pycache__/ipaddress.cpython-310.pyc'
import 'ipaddress' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6694d60>
import 'urllib.parse' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d665bf70>
import 'pathlib' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6659a20>
import 'zipfile' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66091b0>
import 'pwd' # <class '_frozen_importlib.BuiltinImporter'>
import 'grp' # <class '_frozen_importlib.BuiltinImporter'>
import 'distutils.archive_util' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6608dc0>
import 'distutils.cmd' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d677ca30>
# /usr/lib/python3.10/distutils/__pycache__/config.cpython-310.pyc matches /usr/lib/python3.10/distutils/config.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/config.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/configparser.cpython-310.pyc matches /usr/lib/python3.10/configparser.py
# code object from '/usr/lib/python3.10/__pycache__/configparser.cpython-310.pyc'
import 'configparser' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66c9bd0>
import 'distutils.config' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d6609030>
# /usr/lib/python3.10/distutils/__pycache__/extension.cpython-310.pyc matches /usr/lib/python3.10/distutils/extension.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/extension.cpython-310.pyc'
import 'distutils.extension' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66c9a50>
import 'distutils.core' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d718f850>
# /usr/lib/python3.10/distutils/command/__pycache__/__init__.cpython-310.pyc matches /usr/lib/python3.10/distutils/command/__init__.py
# code object from '/usr/lib/python3.10/distutils/command/__pycache__/__init__.cpython-310.pyc'
import 'distutils.command' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fca00>
# /usr/lib/python3.10/distutils/command/__pycache__/build.cpython-310.pyc matches /usr/lib/python3.10/distutils/command/build.py
# code object from '/usr/lib/python3.10/distutils/command/__pycache__/build.cpython-310.pyc'
import 'distutils.command.build' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fca60>
running build
running build_ext
# /usr/lib/python3.10/distutils/command/__pycache__/build_ext.cpython-310.pyc matches /usr/lib/python3.10/distutils/command/build_ext.py
# code object from '/usr/lib/python3.10/distutils/command/__pycache__/build_ext.cpython-310.pyc'
# /usr/lib/python3.10/distutils/__pycache__/sysconfig.cpython-310.pyc matches /usr/lib/python3.10/distutils/sysconfig.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/sysconfig.cpython-310.pyc'
# /usr/lib/python3.10/__pycache__/_sysconfigdata__x86_64-linux-gnu.cpython-310.pyc matches /usr/lib/python3.10/_sysconfigdata__x86_64-linux-gnu.py
# code object from '/usr/lib/python3.10/__pycache__/_sysconfigdata__x86_64-linux-gnu.cpython-310.pyc'
import '_sysconfigdata__x86_64-linux-gnu' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fd540>
import 'distutils.sysconfig' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fd1b0>
import 'distutils.command.build_ext' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fcb50>
# /usr/lib/python3.10/distutils/__pycache__/ccompiler.cpython-310.pyc matches /usr/lib/python3.10/distutils/ccompiler.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/ccompiler.cpython-310.pyc'
import 'distutils.ccompiler' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fd450>
# /usr/lib/python3.10/distutils/__pycache__/unixccompiler.cpython-310.pyc matches /usr/lib/python3.10/distutils/unixccompiler.py
# code object from '/usr/lib/python3.10/distutils/__pycache__/unixccompiler.cpython-310.pyc'
import 'distutils.unixccompiler' # <_frozen_importlib_external.SourceFileLoader object at 0x7709d66fdf30>
building 'trigono' extension
creating build
creating build/temp.linux-x86_64-3.10
x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.10 -c trigonometric.c -o build/temp.linux-x86_64-3.10/trigonometric.o
creating build/lib.linux-x86_64-3.10
x86_64-linux-gnu-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -g -fwrapv -O2 -Wl,-Bsymbolic-functions -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.10/trigonometric.o -o build/lib.linux-x86_64-3.10/trigono.cpython-310-x86_64-linux-gnu.so
# clear builtins._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.__interactivehook__
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup[2] removing sys
# cleanup[2] removing builtins
# cleanup[2] removing _frozen_importlib
# cleanup[2] removing _imp
# cleanup[2] removing _thread
# cleanup[2] removing _warnings
# cleanup[2] removing _weakref
# cleanup[2] removing _io
# cleanup[2] removing marshal
# cleanup[2] removing posix
# cleanup[2] removing _frozen_importlib_external
# cleanup[2] removing time
# cleanup[2] removing zipimport
# destroy zipimport
# cleanup[2] removing _codecs
# cleanup[2] removing codecs
# cleanup[2] removing encodings.aliases
# cleanup[2] removing encodings
# destroy encodings
# cleanup[2] removing encodings.utf_8
# cleanup[2] removing _signal
# cleanup[2] removing _abc
# cleanup[2] removing abc
# cleanup[2] removing io
# cleanup[2] removing __main__
# destroy __main__
# cleanup[2] removing _stat
# cleanup[2] removing stat
# cleanup[2] removing _collections_abc
# cleanup[2] removing genericpath
# cleanup[2] removing posixpath
# cleanup[2] removing os.path
# cleanup[2] removing os
# cleanup[2] removing _sitebuiltins
# cleanup[2] removing types
# cleanup[2] removing importlib._bootstrap
# cleanup[2] removing importlib._bootstrap_external
# cleanup[2] removing warnings
# cleanup[2] removing importlib
# cleanup[2] removing importlib._abc
# cleanup[2] removing itertools
# cleanup[2] removing keyword
# destroy keyword
# cleanup[2] removing _operator
# cleanup[2] removing operator
# destroy operator
# cleanup[2] removing reprlib
# destroy reprlib
# cleanup[2] removing _collections
# cleanup[2] removing collections
# cleanup[2] removing _functools
# cleanup[2] removing functools
# cleanup[2] removing contextlib
# cleanup[2] removing importlib.util
# cleanup[2] removing importlib.machinery
# cleanup[2] removing google
# destroy google
# cleanup[2] removing apport_python_hook
# cleanup[2] removing sitecustomize
# destroy sitecustomize
# destroy apport_python_hook
# cleanup[2] removing site
# destroy site
# cleanup[2] removing enum
# cleanup[2] removing _sre
# cleanup[2] removing sre_constants
# destroy sre_constants
# cleanup[2] removing sre_parse
# cleanup[2] removing sre_compile
# cleanup[2] removing _locale
# cleanup[2] removing copyreg
# cleanup[2] removing re
# cleanup[2] removing token
# destroy token
# cleanup[2] removing tokenize
# cleanup[2] removing linecache
# destroy linecache
# cleanup[2] removing distutils
# cleanup[2] removing distutils.debug
# cleanup[2] removing distutils.errors
# cleanup[2] removing email
# destroy email
# cleanup[2] removing _string
# cleanup[2] removing string
# cleanup[2] removing gettext
# destroy gettext
# cleanup[2] removing getopt
# cleanup[2] removing distutils.fancy_getopt
# cleanup[2] removing distutils.dep_util
# cleanup[2] removing errno
# cleanup[2] removing signal
# cleanup[2] removing _weakrefset
# destroy _weakrefset
# cleanup[2] removing threading
# cleanup[2] removing fcntl
# cleanup[2] removing _posixsubprocess
# cleanup[2] removing select
# cleanup[2] removing collections.abc
# cleanup[2] removing math
# cleanup[2] removing selectors
# cleanup[2] removing subprocess
# cleanup[2] removing distutils.log
# cleanup[2] removing distutils.spawn
# cleanup[2] removing distutils.util
# cleanup[2] removing distutils.dist
# cleanup[2] removing sysconfig
# cleanup[2] removing distutils.dir_util
# cleanup[2] removing distutils.file_util
# cleanup[2] removing binascii
# cleanup[2] removing fnmatch
# cleanup[2] removing zlib
# cleanup[2] removing _compression
# cleanup[2] removing _bz2
# cleanup[2] removing bz2
# cleanup[2] removing _lzma
# cleanup[2] removing lzma
# cleanup[2] removing shutil
# cleanup[2] removing _struct
# cleanup[2] removing struct
# cleanup[2] removing ntpath
# cleanup[2] removing urllib
# destroy urllib
# cleanup[2] removing ipaddress
# cleanup[2] removing urllib.parse
# destroy urllib.parse
# cleanup[2] removing pathlib
# cleanup[2] removing zipfile
# cleanup[2] removing pwd
# cleanup[2] removing grp
# cleanup[2] removing distutils.archive_util
# cleanup[2] removing distutils.cmd
# cleanup[2] removing configparser
# destroy configparser
# cleanup[2] removing distutils.config
# cleanup[2] removing distutils.extension
# cleanup[2] removing distutils.core
# cleanup[2] removing distutils.command
# cleanup[2] removing distutils.command.build
# cleanup[2] removing _sysconfigdata__x86_64-linux-gnu
# destroy _sysconfigdata__x86_64-linux-gnu
# cleanup[2] removing distutils.sysconfig
# cleanup[2] removing distutils.command.build_ext
# cleanup[2] removing distutils.ccompiler
# cleanup[2] removing distutils.unixccompiler
# destroy _sitebuiltins
# destroy importlib._abc
# destroy importlib.util
# destroy importlib.machinery
# destroy distutils.debug
# destroy distutils.errors
# destroy distutils.fancy_getopt
# destroy distutils.spawn
# destroy distutils.dist
# destroy distutils.cmd
# destroy distutils.config
# destroy distutils.extension
# destroy distutils.core
# destroy distutils.command
# destroy distutils.command.build
# destroy distutils.command.build_ext
# destroy distutils.ccompiler
# destroy distutils.unixccompiler
# destroy tokenize
# destroy enum
# destroy sre_compile
# destroy copyreg
# destroy sre_parse
# destroy _sre
# destroy _locale
# destroy getopt
# destroy _string
# destroy string
# destroy distutils
# destroy subprocess
# destroy signal
# destroy selectors
# destroy _signal
# destroy fcntl
# destroy _posixsubprocess
# destroy math
# destroy select
# destroy distutils.util
# destroy distutils.dir_util
# destroy distutils.file_util
# destroy distutils.archive_util
# destroy distutils.dep_util
# destroy sysconfig
# destroy zipfile
# destroy importlib
# destroy shutil
# destroy struct
# destroy threading
# destroy pathlib
# destroy bz2
# destroy lzma
# destroy binascii
# destroy errno
# destroy zlib
# destroy _bz2
# destroy _compression
# destroy _lzma
# destroy _struct
# destroy types
# destroy collections
# destroy ipaddress
# destroy contextlib
# destroy fnmatch
# destroy distutils.sysconfig
# destroy distutils.log
# destroy ntpath
# destroy pwd
# destroy grp
# destroy io
# destroy itertools
# destroy re
# destroy warnings
# cleanup[3] wiping collections.abc
# cleanup[3] wiping functools
# cleanup[3] wiping _functools
# cleanup[3] wiping _collections
# cleanup[3] wiping _operator
# cleanup[3] wiping importlib._bootstrap_external
# cleanup[3] wiping importlib._bootstrap
# cleanup[3] wiping os
# destroy abc
# destroy posixpath
# cleanup[3] wiping genericpath
# cleanup[3] wiping _collections_abc
# cleanup[3] wiping stat
# cleanup[3] wiping _stat
# destroy _stat
# cleanup[3] wiping _abc
# cleanup[3] wiping encodings.utf_8
# cleanup[3] wiping encodings.aliases
# cleanup[3] wiping codecs
# cleanup[3] wiping _codecs
# cleanup[3] wiping time
# cleanup[3] wiping _frozen_importlib_external
# cleanup[3] wiping posix
# cleanup[3] wiping marshal
# cleanup[3] wiping _io
# cleanup[3] wiping _weakref
# cleanup[3] wiping _warnings
# cleanup[3] wiping _thread
# cleanup[3] wiping _imp
# cleanup[3] wiping _frozen_importlib
# cleanup[3] wiping sys
# cleanup[3] wiping builtins
# destroy posix
# destroy _frozen_importlib_external
# destroy _imp
# destroy io
# destroy marshal
# destroy _warnings
# destroy stat
# destroy genericpath
# destroy _collections_abc
# destroy _weakref
# destroy _collections
# destroy collections.abc
# destroy _abc
# destroy _functools
# destroy _operator
# destroy _frozen_importlib
# destroy codecs
# destroy encodings.aliases
# destroy encodings.utf_8
# destroy _codecs
# destroy functools
# destroy time
# destroy builtins
# destroy _thread
# destroy os
# destroy sys
# clear sys.audit hooks
hipper@hipper-G21:~/ex_python$
https://baijiahao.baidu.com/s?id=1775456702040780967&wfr=spider&for=pc