ImportError: cannot import name RAND_egd

蹲街弑〆低调 提交于 2019-11-28 21:31:59

According to Google, it seems to be a very rare Error. I don't know exactly what is wrong but I found a workaround for that so if somebody experiences this problem, maybe this answer helps.

Go to socket.py file and search for RAND_egd. There is a block of code (67th line in my case):

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

Everything what you have to do is to comment the 5 lines:

  #try:
        #from _ssl import RAND_egd
  #except ImportError:
        ## LibreSSL does not provide RAND_egd
        #pass

I don't know why it raises the ImportError because there is a try - except block with pass so the error should not being raised but it helped me to successfully run the exe file.

EDIT: WARNING: I don't know whether it could cause some problems. I experienced no problems yet.

Experienced the same problem.

Solved the problem by removing directories 'dist' and 'build' created by py2exe when it was run on previous version of Python.

Seems like py2exe doesn't rebuild all the files every time. And obviously doesn't catch the fact of Python version changing.

Finally you have a mix of files generated with different versions of Python in your 'dist' directory.

My setup.py is pretty simple:

from distutils.core import setup import py2exe

setup(console=['xxxxxx.py'])

In my case problem was in two installations of Python27: x86 and x64. Only x86 version was in %PATH%, but pip installation script was using files from x64 installation for some reason. Solution was: remove x64, cause I don't really need it.

I found a way to solve it. This might be caused by old version of socket.pyc.

My solutions is edit socket.py, add a space to anywhere and delete then. And then run your setup.py again which will generate new socket.pyc.

Now the problem is solved.

I just remove socket.pyc under c:\Python27\lib, and run py2exe again. The error gone.

I have changed the python version from 2.7.12 to 2.7.9 and problem gone.

It will replace the python files but leave you packages as it is.

Good Luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!