import _socket: "Import Error: DLL load failed"

user3731928 picture user3731928 · Jun 12, 2014 · Viewed 19.2k times · Source

I was attempting to install Django and pymc yesterday. After running into a lot of problems I decided to just re-install 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.

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".

I've re-installed python a couple times now, and have tried the repair option as well, but to no avail. Anyone have any ideas?

EDIT: It seems that when I uninstalled Python, I neglected to delete the C:\Python27 folder. I uninstalled again, deleted the folder, then reinstalled and it works now. Thanks for the help.

Answer

Sascha picture Sascha · Aug 23, 2016

I had the same error afters upgrading to 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". 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.

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.