Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

python - ImportError: cannot import name RAND_egd

I've tried to create an exe file using py2exe. I've recently updated Python from 2.7.7 to 2.7.10 to be able to work with requests - proxies.

Before the update everything worked fine but now, the exe file recently created, raising this error:

    Traceback (most recent call last):
  File "puoka_2.py", line 1, in <module>
    import mLib
  File "mLib.pyc", line 4, in <module>
  File "urllib2.pyc", line 94, in <module
  File "httplib.pyc", line 71, in <module
  File "socket.pyc", line 68, in <module>
ImportError: cannot import name RAND_egd

It could be probably repaired by changing options in setup.py file but I can't figure out what I have to write there. I've tried options = {'py2exe': {'packages': ['requests','urllib2']}}) but with no success.

It works as a Python script but not as an exe.

Do anybody knows what to do?

EDIT:

I've tried to put into setup.py file this import: from _ssl import RAND_egd and it says that it can't be imported.

EDIT2: Setup.py:

from distutils.core import setup
import py2exe
# from _ssl import RAND_egd
setup(
  console=['puoka_2.py'],
  options = {'py2exe': {'packages': ['requests']}})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...