简体   繁体   English

import _socket:“导入错误:DLL 加载失败”

[英]import _socket: "Import Error: DLL load failed"

I was attempting to install Django and pymc yesterday.我昨天试图安装 Django 和 pymc。 After running into a lot of problems I decided to just re-install Python 2.7.遇到很多问题后,我决定重新安装 Python 2.7。 I've done that but am now having problems import almost anything.我已经做到了,但现在导入几乎任何东西都遇到了问题。 I get a bunch of lines, the last of which are:我得到一堆线,最后一行是:

 File "c:\python27\lib\httplib.py", line 71, in <module>
   import socket
 File "c:\python27\lib\socket.py", line 47, in <module>
   import _socket
ImportError: DLL load failed: The specified procedure could not be found.

Whether I run python in the command prompt (which works) and try to do import pip , or type outside of the shell python get-pip.py I get those same last lines.无论我是在命令提示符下运行 python(有效)并尝试执行import pip ,还是在 shell python get-pip.py之外键入,我都会得到相同的最后几行。

I should state for the record that I have two versions of python on my machine, one being 2.7, and the other being I THINK 2.6 located in a canopy folder, but that doesn't work either, giving an error message of `ImportError: No module named os". I have my PATH environment variable leading with "c:\python27;c:\python27\scripts".我应该 state 作为记录,我的机器上有两个版本的 python,一个是 2.7,另一个是我认为位于 canopy 文件夹中的 2.6,但这也不起作用,给出错误消息 `ImportError:没有名为 os 的模块。我的 PATH 环境变量以“c:\python27;c:\python27\scripts”开头。

I've re-installed python a couple times now, and have tried the repair option as well, but to no avail.我已经重新安装了几次 python,也尝试了修复选项,但无济于事。 Anyone have any ideas?有人有主意吗?

EDIT: It seems that when I uninstalled Python, I neglected to delete the C:\Python27 folder.编辑:似乎当我卸载 Python 时,我忽略了删除 C:\Python27 文件夹。 I uninstalled again, deleted the folder, then reinstalled and it works now.我再次卸载,删除文件夹,然后重新安装,现在可以使用了。 Thanks for the help.谢谢您的帮助。

I had the same error afters upgrading to python 2.7.12. 升级到python 2.7.12之后我遇到了同样的错误。

To solve it, I did another install into the same directory. 为了解决这个问题,我在同一目录中进行了另一次安装。 Interestingly enough, the installer did not recognize the existing installation. 有趣的是,安装程序无法识别现有安装。 I made sure to check "add python.exe to Path". 我确保检查“将python.exe添加到路径”。 After that, it worked. 在那之后,它奏效了。

Attempting to install python 2.7.12 again, the installer recognized the existing installation and offered me change/repair/uninstall options. 尝试再次安装python 2.7.12,安装程序识别出现有安装,并提供了更改/修复/卸载选项。

Update: In retrospective, the reason might have been, that I unintentionally mixed a 32-bit installation with a 64-bit update (or vice versa). 更新:在回顾中,原因可能是,我无意中将32位安装与64位更新混合(反之亦然)。 Python doesn't seem to install into different directories or use different DLL-names. Python似乎没有安装到不同的目录或使用不同的DLL名称。 The installer doesn't warn you either. 安装程序也不会警告您。 So after the update, your DLLs are a unhealthy mix of 32 and 64-bit variants. 所以在更新之后,你的DLL是32位和64位变体的不健康混合。

I have the same problem, after I mix py2 & py3 enviroment(windows 10), sovled it by: 我有同样的问题,在我混合py2和py3环境(windows 10)后,通过以下方式解决它:

1. Uninstall all py2 & py3
2. install py 2.7.14 win32 (now newest)
3. add following enviroment varaible to system Path & PythonPath:
1) C:\Python27
2) C:\Python27\Script
3) C:\Python27\Lib
4) C:\Python27\DLLs

ref: here 参考: 这里

I just solved the problem by adding the following in the env variables:我刚刚通过在环境变量中添加以下内容解决了这个问题:

PYTHONHOME : C:\Python39\apps\Python39

I would suggest getting, PyWin32 or either PyWin64, depending on your System architecture. 我建议使用PyWin32或PyWin64,具体取决于您的系统架构。 If your system is x86, get PyWin32, otherwise get PyWin64 if your system is x64. 如果您的系统是x86,请获取PyWin32,否则如果您的系统是x64则获取PyWin64。 I have similar problems myself and getting PyWin32 helped me out in fixing these problems. 我自己也有类似的问题,让PyWin32帮助我解决了这些问题。

import sys
sys.path.append("address where the socket module is present like C:\Python34\Lib\")
import socket

try this it might work 试试这可能会奏效

This seems to be an issue with Python 2.7.13 as this moment. 这一点似乎是Python 2.7.13的一个问题。 Installing 2.7.12 fixed it for me. 安装2.7.12为我修好了。

Actually its look like import _socket calls is been failed which is causing this error ImportError: DLL load failed 实际上它看起来像import _socket调用失败,导致此错误ImportError:DLL加载失败

The get-pip.py the function b85decode() is trying to import the _socket which is not found , The Solution to this is you can install any 3.X version and run the get-pip.py which should resolve the issue and get pip installed. get-pip.py函数b85decode()试图导入找不到的_socket,解决方案是你可以安装任何3.X版本并运行get-pip.py来解决问题并得到pip安装。

C:\\Python33>python.exe C:\\get-pip.py C:\\ Python33> python.exe C:\\ get-pip.py

Collecting pip Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB) 100% |################################| 收集点子下载pip-7.1.2-py2.py3-none-any.whl(1.1MB)100%| ######################### ####### | 1.1MB 197kB/s 1.1MB 197kB / s

Installing collected packages: pip, setuptools, wheel Successfully installed pip-7.1.2 setuptools-18.5 wheel-0.26.0 安装收集的软件包:pip,setuptools,wheel成功安装pip-7.1.2 setuptools-18.5 wheel-0.26.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM