python 2.7.12报ImportError: No module named _socket

最近在做一个smpp的python库,由于RF依赖Python2,于是从python3切换到python2,运行代码提示:

File "C:\Python27\lib\socket.py", line 47, in <module>

    import _socket

ImportError: No module named _socket

百度了一下,在https://stackoverflow.com/questions/24173487/import-socket-import-error-dll-load-failed 这个页面看到了解决方法:重新安装python 2.7.12,有人说是32位和64位操作系统的问题,下面是这些人的解释:

Attempting to install python 2.7.12 again, the installer recognized the existing installation and offered me change/repair/uninstall options.
Update: In retrospective, the reason might have been, that I unintentionally mixed a 32-bit installation with a 64-bit update (or vice versa). Python doesn't seem to install into different directories or use different DLL-names. The installer doesn't warn you either. So after the update, your DLLs are a unhealthy mix of 32 and 64-bit variants.



I would suggest getting, PyWin32 or either PyWin64, depending on your System architecture. If your system is x86, get PyWin32, otherwise get PyWin64 if your system is x64. I have similar problems myself and getting PyWin32 helped me out in fixing these problems.


我的电脑是64位的,于是去https://www.python.org/downloads/release/python-2712/下载了64位的安装包,重新安装了python 2.7.12,问题解决。

发布了99 篇原创文章 · 获赞 60 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/lengyuewusheng99/article/details/78121287