Getting error: DLL load failed: The operating syst

2019-01-25 10:27发布

I cannot successfully run the first command in the Scrapy tutorial (http://doc.scrapy.org/en/latest/intro/tutorial.html). The code copy pasted below is the result (with the error at the end).

Python 2.7 is installed, and I followed the installation instructions for scrapy (http://doc.scrapy.org/en/latest/intro/install.html). I am running Python 2.7.6 32 bit on Windows 7 (64 bit).

Other aspects of installation:

  1. Twisted-13.2.0.dist-info
  2. zope.interface-4.1.1-py2.7
  3. Scrapy-0.22.2-py2.7
  4. lxml-3.3.3-py2.7
  5. cssselect-0.9.1-py2.7
  6. cryptography-0.3.dist-info
  7. pyOpenSSL-0.14-py2.7
  8. pywin32_system32

And here's the error message:

C:\Python27\Scripts>scrapy startproject tutorial
    Traceback (most recent call last):
      File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
      File "C:\Python27\lib\runpy.py", line 72, in _run_code
        exec code in run_globals
      File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 9, in <module>
        from scrapy.crawler import CrawlerProcess
      File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 3, in <module>
        from twisted.internet import reactor, defer
      File "twisted\internet\reactor.py", line 38, in <module>
        from twisted.internet import default
      File "twisted\internet\default.py", line 56, in <module>
        install = _getInstallFunction(platform)
      File "twisted\internet\default.py", line 50, in _getInstallFunction
        from twisted.internet.selectreactor import install
      File "twisted\internet\selectreactor.py", line 18, in <module>
        from twisted.internet import posixbase
      File "twisted\internet\posixbase.py", line 24, in <module>
        from twisted.internet import error, udp, tcp
      File "twisted\internet\tcp.py", line 29, in <module>
        from twisted.internet._newtls import (
      File "twisted\internet\_newtls.py", line 21, in <module>
        from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
      File "twisted\protocols\tls.py", line 40, in <module>
        from OpenSSL.SSL import Error, ZeroReturnError, WantReadError
      File "build\bdist.win32\egg\OpenSSL\__init__.py", line 8, in <module>
      File "build\bdist.win32\egg\OpenSSL\rand.py", line 11, in <module>
      File "build\bdist.win32\egg\OpenSSL\_util.py", line 4, in <module>
      File "C:\Python27\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py",      l3, in __init__
      self._ensure_ffi_initialized()
      File "C:\Python27\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", l9, in _ensure_ffi_initialized libraries)
      File "C:\Python27\lib\site-packages\cryptography\hazmat\bindings\utils.py", line 77, ind_ffi
        ext_package="cryptography",
      File "C:\Python27\lib\site-packages\cffi\api.py", line 341, in verify
        lib = self.verifier.load_library()
      File "C:\Python27\lib\site-packages\cffi\verifier.py", line 75, in load_library
        return self._load_library()
      File "C:\Python27\lib\site-packages\cffi\verifier.py", line 151, in _load_library
        return self._vengine.load_library()
      File "C:\Python27\lib\site-packages\cffi\vengine_cpy.py", line 138, in load_library
        raise ffiplatform.VerificationError(error)

cffi.ffiplatform.VerificationError: importing 'C:\\Python27\\lib\\site-packages\\cryptogr
\_Cryptography_cffi_48bbf0ebx93c91939.pyd': DLL load failed: The operating system cannot
1.**

9条回答
爷的心禁止访问
2楼-- · 2019-01-25 11:16

I ran across this error today on a Windows 7 system. The problem for me was similar to @user2314737, @voetsjoeba, and @Olegp. libeay32.dll and ssleay32.dll where in folders related to Intel that were in the Windows path environmental variable.

Unfortunately, my system is locked (work computer), so I could not move the files or alter the system's path variable. Instead, I manually removed the Intel related items from the path variable that Python accesses using:

import os
os.environ['path'] = ';'.join(
    filter(lambda x: 'intel' not in x.lower(), os.environ['path'].split(';'))
    )
import OpenSSL
查看更多
Bombasti
3楼-- · 2019-01-25 11:21

As already mentioned in the other answers, the issue is caused by the two files ssleay32.dll and libeay32.dll. The error occurred when importing OpenSSL in Python

>>> from OpenSSL import crypto, SSL
  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
ImportError: DLL load failed: The operating system cannot run %1.

Here's how I solved the issue on Windows 10. If you have git for Windows (download here) you can just copy these two files from Git\mingw64\bin\ to some location in your path. What worked for me was to copy them to c:\Windows (or else to the folder from which you're starting Python).

To find the locations of the dll files type at a cmd prompt:

>where libeay32.dll
C:\Program Files (x86)\Intel\TXE Components\TCS\libeay32.dll
...
C:\Users\me\AppData\Local\Programs\Git\mingw64\bin\libeay32.dll
查看更多
smile是对你的礼貌
4楼-- · 2019-01-25 11:22

@lambokini is right,but i'cant comment on the answer, so come this one.

First download openssl source from http://www.openssl.org/

Second start "Visual Studio Command Prompt", compile and install openssl follow install guide(INSTALL.W32 or INSTALL.W64).

Then add "[openssl install path]\bin" to the environment variable "path", and you can delete ssleay32.dll and libeay32.dll under system32.

Notice: dll will be load from the first place it seached. for exmple: Path=xxx;d:\PHP5;d:\openssl\bin; if ssleay32.dll and libeay32.dll also appears under PHP5, then python will load that one.

查看更多
登录 后发表回答