5
0

More than 3 years have passed since last update.

M2Crypto を python3から使おうと「pip install M2Crypto」したらエラーが出た

Last updated at Posted at 2019-12-28

背景

  • Ubuntu 18.04 に M2Cryptoを入れてpython3から使おうとしたら、必要なパッケージが入っていなくてエラーがでた。
  • 環境
    • Ubuntu 18.04.3 LTS
    • Python 3.6.9
    • (python2系は入っていない)

結論: インストール方法

$ sudo apt-get install build-essential python3-dev openssl libssl-dev swig
$ pip install M2Crypto

のように、必要なパッケージをapt-getで入れておけば問題なし。

step by step で入れようとした時のエラー

  • エラーメッセージでググってもドンピシャのページが見つからなかったので、メモを残しておく。

  • c++ (またはbuild-essential)が入っていない
error: [Errno 2] No such file or directory: 'cpp': 'cpp'

と出てインストールできなかったら、
$ sudo apt-get install cpp


  • gcc (またはbuild-essential)が入っていない
    unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

と出てインストールできなかったら、
$ sudo apt-get install gcc


  • python3-develが入っていない
    SWIG/_m2crypto_wrap.c:127:10: fatal error: Python.h: No such file or directory
     #include <Python.h>
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

と出てインストールできなかったら、
$ sudo apt-get install python3-dev


  • openssl, libssl-devが入っていない
    SWIG/_m2crypto_wrap.c:3561:10: fatal error: openssl/err.h: No such file or directory
     #include <openssl/err.h>
              ^~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

と出てインストールできなかったら、
$ sudo apt-get install openssl libssl-dev


  • swigが入っていない
    SWIG/_m2crypto_wrap.c:31151:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
         (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]
     static PyHeapTypeObject SwigPyBuiltin___cbd_t_type = {
                                                          ^
    SWIG/_m2crypto_wrap.c:31150:5:
         (PyObject*) 0,                            /* ht_name */
         {
    SWIG/_m2crypto_wrap.c:31152:1:
     };
     }
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

と出てインストールできなかったら、
$ sudo apt-get install swig
(3.0.12-1が入った)


  • この後も続きそうですが、上述のインストール方法のように普通に必要パッケージを入れてからM2Cryptoを入れました。
5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0