Skip to main content
 首页 » 编程设计

python之netifaces 包在 Linux 上的 Python3.4 下不起作用

2024年10月24日14xing901022

我在 Mac OS 上开发了我的应用程序,它运行良好。在 Mac 上我得到这个:

$ python3 
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)  
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import netifaces 
>>> netifaces.version 
'0.10.4' 
>>> netifaces.interfaces() 
['lo0', 'gif0', 'stf0', 'en0', 'en1', 'en2', 'bridge0', 'p2p0', 'awdl0', 'utun1', 'utun0'] 

太棒了。当我将应用程序移动到 Linux 时它不起作用——我得到这个:

~$ python3 
Python 3.4.3 (default, Jun 17 2015, 22:58:00)  
[GCC 4.6.3] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import netifaces 
>>> netifaces.version 
'0.10.4'     
>>> netifaces.interfaces() 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
OSError: [Errno 0] Error 
>>>  

我在 sudo 下试了一下,得到了同样的结果。

由于找不到包含 Python3 的存储库,我最终从源代码构建了 Python3.4 安装。有没有可能我在 netifaces 需要的构建中遗漏了一些东西?

除此之外,还有人知道如何进行吗?

更新:我的 Linux 是 Ubuntu 12.04(别问我卡在那里一段时间了)并且 uname -a 显示:

Linux testsys 3.2.16oa4 #1 SMP Tue Jan 6 16:12:02 PST 2015 x86_64 x86_64 x86_64 GNU/Linux 

请您参考如下方法:

请包括您的 Linux 信息:发行版、版本。

问题的存在很可能是因为您已经从源代码构建了 Python 3.4,并且 Python 需要分发特定的补丁才能在您的特定版本的 Linux 上正常工作。这些补丁可能会从 python.org 上分发的源代码中省略。请咨询您的分发问题跟踪器。

对于 Ubuntu,在安装 Python 时使用 deadsnakes 存储库:

https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes