You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3.11.5执行pip install pcapy时遇AttributeError错误求助

安装pcapy时出现AttributeError错误

我执行pip install pcapy命令安装pcapy,持续出现以下错误:

Collecting pcapy
  Using cached pcapy-0.11.4.tar.gz (37 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/q_/sgpdqy3d3wj_w3s3jfctw14r0000gn/T/pip-install-xxth8wkc/pcapy_ad5b43f8a92c48fe80e1260f891552a3/setup.py", line 49, in <module>
          save_init_posix = sysconfig._init_posix
                            ^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'distutils.sysconfig' has no attribute '_init_posix'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

已更新wheel和pip,当前Python版本为3.11.5。


解决方法

  • 推荐方案:安装兼容Python 3.11的替代包pcapy-ng,执行命令:
    pip install pcapy-ng
    
  • 若必须使用原版pcapy,可将Python版本降级至3.10及以下,再执行pip install pcapy
  • 不推荐的临时修复:手动修改pcapy源码的setup.py,删除或注释掉引用sysconfig._init_posix的代码,但可能引发其他兼容性问题

内容的提问来源于stack exchange,提问作者B5AK27

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:41:18