fatal error: openssl/err.h: No such file or directory - Python

fatal error: openssl/err.h: No such file or directory - Python

我尝试安装 M2Crypto,但我无法安装,我遇到的错误如下: 我在一个虚拟的 miniconda 环境中。

building 'M2Crypto._m2crypto' extension
gcc -pthread -B /home/lcteen/miniconda3/envs/django/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/lcteen/miniconda3/envs/django/include/python3.7m -I/home/lcteen/Downloads/M2Crypto-0.35.2/SWIG -c SWIG/_m2crypto_wrap.c -o build/temp.linux-x86_64-3.7/SWIG/_m2crypto_wrap.o -DTHREADING -Wno-deprecated-declarations
SWIG/_m2crypto_wrap.c:3561:10: fatal error: openssl/err.h: No such file or directory
 3561 | #include <openssl/err.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

我正在使用以下命令安装它:python setup.py install


pip安装时报错如下:

Collecting M2Crypto
  Using cached https://files.pythonhosted.org/packages/74/18/3beedd4ac48b52d1a4d12f2a8c5cf0ae342ce974859fba838cbbc1580249/M2Crypto-0.35.2.tar.gz
Building wheels for collected packages: M2Crypto
  Building wheel for M2Crypto (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/lcteen/miniconda3/envs/django/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-kjvnl1i1 --python-tag cp37
       cwd: /tmp/pip-install-q5bgx0sr/M2Crypto/
  Complete output (52 lines):
  running bdist_wheel
  running build
  running build_py
  copying M2Crypto/Engine.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/RC4.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/BIO.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/m2.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/m2urllib2.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/BN.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/util.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/Err.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/EC.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/DSA.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/EVP.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/m2urllib.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/httpslib.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/callback.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/m2xmlrpclib.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/RSA.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/threading.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/__init__.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/m2crypto.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/X509.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/ftpslib.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/Rand.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/AuthCookie.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/ASN1.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/SMIME.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/six.py -> build/lib.linux-x86_64-3.7/M2Crypto
  copying M2Crypto/DH.py -> build/lib.linux-x86_64-3.7/M2Crypto
  creating build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/Cipher.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/ssl_dispatcher.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/timeout.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/SSLServer.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/cb.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/Context.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/Checker.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/TwistedProtocolWrapper.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/__init__.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/Session.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  copying M2Crypto/SSL/Connection.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
  running build_ext
  building 'M2Crypto._m2crypto' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/SWIG
  gcc -pthread -B /home/lcteen/miniconda3/envs/django/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/lcteen/miniconda3/envs/django/include/python3.7m -I/tmp/pip-install-q5bgx0sr/M2Crypto/SWIG -c SWIG/_m2crypto_wrap.c -o build/temp.linux-x86_64-3.7/SWIG/_m2crypto_wrap.o -Wno-deprecated-declarations -DTHREADING
  SWIG/_m2crypto_wrap.c:3561:10: fatal error: openssl/err.h: No such file or directory
   3561 | #include <openssl/err.h>
        |          ^~~~~~~~~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for M2Crypto
  Running setup.py clean for M2Crypto
Failed to build M2Crypto
Installing collected packages: M2Crypto
    Running setup.py install for M2Crypto ... error
    ERROR: Command errored out with exit status 1:
     command: /home/lcteen/miniconda3/envs/django/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-8ojxmrjt/install-record.txt --single-version-externally-managed --compile
         cwd: /tmp/pip-install-q5bgx0sr/M2Crypto/
    Complete output (55 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/Engine.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/RC4.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/BIO.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/m2.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/m2urllib2.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/BN.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/util.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/Err.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/EC.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/DSA.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/EVP.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/m2urllib.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/httpslib.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/callback.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/m2xmlrpclib.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/RSA.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/threading.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/__init__.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/m2crypto.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/X509.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/ftpslib.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/Rand.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/AuthCookie.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/ASN1.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/SMIME.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/six.py -> build/lib.linux-x86_64-3.7/M2Crypto
    copying M2Crypto/DH.py -> build/lib.linux-x86_64-3.7/M2Crypto
    creating build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/Cipher.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/ssl_dispatcher.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/timeout.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/SSLServer.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/cb.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/Context.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/Checker.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/TwistedProtocolWrapper.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/__init__.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/Session.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    copying M2Crypto/SSL/Connection.py -> build/lib.linux-x86_64-3.7/M2Crypto/SSL
    running build_ext
    building 'M2Crypto._m2crypto' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/SWIG
    gcc -pthread -B /home/lcteen/miniconda3/envs/django/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/lcteen/miniconda3/envs/django/include/python3.7m -I/tmp/pip-install-q5bgx0sr/M2Crypto/SWIG -c SWIG/_m2crypto_wrap.c -o build/temp.linux-x86_64-3.7/SWIG/_m2crypto_wrap.o -Wno-deprecated-declarations -DTHREADING
    SWIG/_m2crypto_wrap.c:3561:10: fatal error: openssl/err.h: No such file or directory
     3561 | #include <openssl/err.h>
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/lcteen/miniconda3/envs/django/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q5bgx0sr/M2Crypto/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-8ojxmrjt/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

我正在使用 python 3.7

我已经执行了以下命令,但仍然无法安装:

sudo apt-get install python3-dev

有什么解决办法吗?


更新:

调查错误,我看到以下命令可以解决它:

sudo apt-get install libssl-dev

我运行安装了还是安装不上,只是报错不同。错误:

SWIG/_m2crypto_wrap.c:31130:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_mapping’)
    SWIG/_m2crypto_wrap.c:31134:5: warning: excess elements in struct initializer
    31134 |     (objobjproc) 0,                           /* sq_contains */
          |     ^
    SWIG/_m2crypto_wrap.c:31134:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_mapping’)
    SWIG/_m2crypto_wrap.c:31135:5: warning: excess elements in struct initializer
    31135 |     (binaryfunc) 0,                           /* sq_inplace_concat */
          |     ^
    SWIG/_m2crypto_wrap.c:31135:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_mapping’)
    SWIG/_m2crypto_wrap.c:31136:5: warning: excess elements in struct initializer
    31136 |     (ssizeargfunc) 0,                         /* sq_inplace_repeat */
          |     ^
    SWIG/_m2crypto_wrap.c:31136:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_mapping’)
    SWIG/_m2crypto_wrap.c:31146:5: warning: initialization of ‘Py_ssize_t (*)(PyObject *)’ {aka ‘long int (*)(struct _object *)’} from incompatible pointer type ‘int (*)(PyObject *, Py_buffer *, int)’ {aka ‘int (*)(struct _object *, struct bufferinfo *, int)’} [-Wincompatible-pointer-types]
    31146 |     (getbufferproc) 0,                        /* bf_getbuffer */
          |     ^
    SWIG/_m2crypto_wrap.c:31146:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_sequence.sq_length’)
    SWIG/_m2crypto_wrap.c:31147:5: warning: initialization of ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} from incompatible pointer type ‘void (*)(PyObject *, Py_buffer *)’ {aka ‘void (*)(struct _object *, struct bufferinfo *)’} [-Wincompatible-pointer-types]
    31147 |     (releasebufferproc) 0,                    /* bf_releasebuffer */
          |     ^
    SWIG/_m2crypto_wrap.c:31147:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_sequence.sq_concat’)
    SWIG/_m2crypto_wrap.c:31150:5: warning: initialization of ‘int (*)(PyObject *, Py_buffer *, int)’ {aka ‘int (*)(struct _object *, struct bufferinfo *, int)’} from incompatible pointer type ‘PyObject *’ {aka ‘struct _object *’} [-Wincompatible-pointer-types]
    31150 |     (PyObject*) 0,                            /* ht_name */
          |     ^
    SWIG/_m2crypto_wrap.c:31150:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_buffer.bf_getbuffer’)
    SWIG/_m2crypto_wrap.c:31151:5: warning: initialization of ‘void (*)(PyObject *, Py_buffer *)’ {aka ‘void (*)(struct _object *, struct bufferinfo *)’} from incompatible pointer type ‘PyObject *’ {aka ‘struct _object *’} [-Wincompatible-pointer-types]
    31151 |     (PyObject*) 0,                            /* ht_slots */
          |     ^
    SWIG/_m2crypto_wrap.c:31151:5: note: (near initialization for ‘SwigPyBuiltin___cbd_t_type.as_buffer.bf_releasebuffer’)
    SWIG/_m2crypto_wrap.c:30993:54: warning: missing braces around initializer [-Wmissing-braces]
    30993 | static PyHeapTypeObject SwigPyBuiltin___cbd_t_type = {
          |                                                      ^
    ......
    31150 |     (PyObject*) 0,                            /* ht_name */
          |     {
    31151 |     (PyObject*) 0,                            /* ht_slots */
    31152 | };
          | }
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/lcteen/miniconda3/envs/django/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-o4e0dlzd/M2Crypto/setup.py'"'"'; __file__='"'"'/tmp/pip-install-o4e0dlzd/M2Crypto/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lntmgt5e/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

(因为太长了所以没有把错误全都写出来)

问题的解决方案是运行以下命令:

conda install -c conda-forge m2crypto