为什么Python不能在这里发现BoostPrettyPrinter模块?

2024-06-16 10:06:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让Boost-Pretty-Printer工作,但是GDB拒绝了文档化的安装过程(下面的测试用例中显示了相同的错误)。在

我单独尝试了Python脚本,由于我不是Pythonista,因此无法理解导入失败的原因:

[root@localhost daemon]# ls -l ~/Boost-Pretty-Printer/
total 16
drwxr-xr-x. 2 root root 4096 Mar  5 16:00 boost
drwxr-xr-x. 2 root root 4096 Mar  5 16:00 examples
-rw-r--r--. 1 root root 3197 Mar  5 16:00 README.org
-rw-r--r--. 1 root root  989 Mar  5 16:00 supported.txt
[root@localhost daemon]# ls -l ~/Boost-Pretty-Printer/boost
total 48
-rw-r--r--. 1 root root     0 Mar  5 16:00 __init__.py
-rw-r--r--. 1 root root 48582 Mar  5 16:00 printers.py
[root@localhost daemon]# cat ~/.gdbinit
#python
import sys
sys.path.insert(0, '~/Boost-Pretty-Printer')
from boost.printers import register_printer_gen
register_printer_gen(None)
end

[root@localhost daemon]# python ~/.gdbinit
Traceback (most recent call last):
  File "/root/.gdbinit", line 4, in <module>
    from boost.printers import register_printer_gen
ImportError: No module named boost.printers

为什么找不到模块?在


Tags: importregisterlocalhostprettyrootprintermardaemon
1条回答
网友
1楼 · 发布于 2024-06-16 10:06:15

~的魔力在于这里没有的shell特性,因此您必须完整地写出路径。在

在这种情况下:

sys.path.insert(0, '/root/Boost-Pretty-Printer')

或者,更灵活地使用^{}~替换为用户的主目录:

^{pr2}$

相关问题 更多 >