当安装 pip install netifaces后
目录下会有site-packages\netifaces.cp38-win_amd64.pyd
import socket
import traceback
import netifaces
import stu_class_info
def get_network_interfaces():
interfaces = netifaces.interfaces()
print(netifaces.interfaces)
print(netifaces.__file__) #for check the path of pyd
result = {}
import netifaces后,ctrl+B可打开netifaces.py
netifaces.py与netifaces.cp38-win_amd64.pyd名字并不相同,为什么能找到并加载?
-
原因 :Python 在查找扩展模块时,会自动尝试多种命名变体!
-
netifaces.cp38-win_amd64.pyd则是变体
-
Python 会自动在sys.path尝试
netifaces.*.pyd等变体 -
sys.path则包含有site-packages目录
-
可通过
print(sys.path),显示查找哪些目录,如:site-packages,Lib,项目目录等