Pwntools No module named 'elftools.common.py3compat' 问题解决办法

7erry

Pwntools No module named ‘elftools.common.py3compat’ 问题解决办法

学pwn的时候下载了pwntools,正打算在Ipython里import pwn美美把玩时,出现了报错No module named ‘elftools.common.py3compat’。

1
2
3
2023.9.22更新
一个写的非常好的解决pwntools相关问题的博客地址是
[https://www.cnblogs.com/pcat/p/5451780.html](https://www.cnblogs.com/pcat/p/5451780.html)

上网搜索了一下,发现给出的解决方式都是单纯的安装pyelftools模块。尝试进行安装后发现该模块已安装,pip3 show pyelftools得到输出

1
2
3
4
5
6
7
8
9
10
Name: pyelftools
Version: 0.30
Summary: Library for analyzing ELF files and DWARF debugging information
Home-page: https://github.com/eliben/pyelftools
Author: Eli Bendersky
Author-email: eliben@gmail.com
License: Public domain
Location: /Library/Python/3.9/site-packages
Requires:
Required-by: pwntools

似乎没有什么问题。查看import pwn的报错信息

1
2
3
---> 79 from elftools.common.py3compat import bytes2str
80 from elftools.common.utils import roundup
81 from elftools.common.utils import struct_parse

仔细思索后决定逐级查看模块

1
ls /Library/Python/3.9/site-packages/elftools

得到结果

1
__init__.py common      construct   dwarf       ehabi       elf

1
ls /Library/Python/3.9/site-packages/elftools/common

成功发现问题

1
__init__.py        construct_utils.py exceptions.py      utils.py

确实没有py3compat文件。
看了看pyelftools的仓库,发现在0.30版本的更新中,py3compat文件被合并到了utils.py
因此,可以把from elftools.common.py3compat import bytes2str改为from elftools.common.utils import bytes2str,又或者运行

1
2
pip3 uninstall pyelftools
pip3 install pyelftools==0.29

即可

  • Title: Pwntools No module named 'elftools.common.py3compat' 问题解决办法
  • Author: 7erry
  • Created at : 2023-09-12 00:00:00
  • Updated at : 2023-09-22 00:00:00
  • Link: http://7erry.com/2023/09/12/Pwntools-No-module-named-elftools-common-py3compat-问题解决办法/
  • License: This work is licensed under CC BY-NC 4.0.
On this page
Pwntools No module named 'elftools.common.py3compat' 问题解决办法