オープンデータとプログラミング

Py2exeでエラー:ImportError: cannot import name RAND_egd

python

Pythonを2.7.10にアップデートしたら、py2exeでパッケージングしたEXEで以下のエラー。対処方法のメモを残しておく。

Traceback (most recent call last):
  File "price_check.py", line 13, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\__init__.pyo", line 26, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\workbook\__init__.pyo", line 5, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\workbook\workbook.pyo", line 13, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\writer\write_only.pyo", line 17, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\writer\excel.pyo", line 30, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "openpyxl\packaging\manifest.pyo", line 7, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "mimetypes.pyo", line 29, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "urllib.pyo", line 26, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "socket.pyo", line 68, in <module>
ImportError: cannot import name RAND_egd

py2exeはとてもありがたいのだが、この手のエラーが多いのが困る。

暫定的な対応だがsocket.pyRAND_egdをimportしているところをコメントアウトしたらエラーが解消された。

    # we need to import the same constants we used to...
    from _ssl import SSLError as sslerror
    from _ssl import \
         RAND_add, \
         RAND_status, \
         SSL_ERROR_ZERO_RETURN, \
         SSL_ERROR_WANT_READ, \
         SSL_ERROR_WANT_WRITE, \
         SSL_ERROR_WANT_X509_LOOKUP, \
         SSL_ERROR_SYSCALL, \
         SSL_ERROR_SSL, \
         SSL_ERROR_WANT_CONNECT, \
         SSL_ERROR_EOF, \
         SSL_ERROR_INVALID_ERROR_CODE

''' ↓★コメントアウトする
   try:
        from _ssl import RAND_egd
    except ImportError:
        # LibreSSL does not provide RAND_egd
        pass
'''

Comments are closed.