Python将回调函数转为可迭代对象|convert callback into generator in Python

如今各种语法糖越来越方便,以前很多难以直观理解的代码,通过语法糖包装下,变得越来越好用,典型的有 lambda表达式,协程, flow, rx 等等,用起来是不亦乐乎。

很对第三方sdk也逐渐从传统的callbck形式逐渐提供flow形式的接口,让适用方能够比较自然的接入。

Continue reading “Python将回调函数转为可迭代对象|convert callback into generator in Python”

Python如何将pdf导出图片格式

有些时候,我们不得不导出pdf,一些软件会要求购买vip服务才行,但是如果你装了python环境的话,其实现成的包就能帮你完成这个操作。

第一步需要安装fitz和PyMuPDF

大概三十多M。国内网络比较差的情况下可以使用清华源 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install fitz -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install PyMuPDF
Continue reading “Python如何将pdf导出图片格式”

undefined symbol: _ZN15TracebackLoggerC1EPKc, version libcudnn_ops_infer.so.8 错误 解决方法

python: symbol lookup error: /data/home/xxxxxproject/venv/lib/python3.9/site-packages/torch/lib/../../nvidia/cudnn/lib/libcudnn_cnn_infer.so.8: undefined symbol: _ZN15TracebackLoggerC1EPKc, version libcudnn_ops_infer.so.8

如果你遇到上面错误,可以ldd看一下libcudnn_ops_infer.so.8 指向的不是我们的venv下的目标so

ldd /data/home/projxxx/venv/lib/python3.9/site-packages/torch/lib/../../nvidia/cudnn/lib/libcudnn_cnn_infer.so.8
ldd: warning: you do not have execution permission for `/data/home/xxxxxxxproject/venv/lib/python3.9/site-packages/torch/lib/../../nvidia/cudnn/lib/libcudnn_cnn_infer.so.8'
        linux-vdso.so.1 (0x00007ffcee0e1000)
        /$LIB/libonion_block.so => /lib64/libonion_block.so (0x00007f81c7053000)
        /$LIB/libonion.so => /lib64/libonion.so (0x00007f81ee291000)
        libcudnn_ops_infer.so.8 => /usr/local/cuda-11.0/lib64/libcudnn_ops_infer.so.8 (0x00007f81b5507000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f81b52f0000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f81b50e7000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f81b4ec7000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f81b4cc3000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f81b4b2b000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f81b47a9000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f81ee261000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f81b43e7000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f81ee172000)

可以看到,libcudnn_ops_infer 并非指像我们虚拟环境下的路径,可以重新指定搜索路径

export LD_LIBRARY_PATH=~/projectxxxxxx/venv/lib/python3.9/site-packages/nvidia/cudnnib:$LD_LIBRARY_PATH

上面xxxxxx 就是你的项目地址, venv是虚拟环境目录