'import sitecustomize' failed upon starting spyder

被刻印的时光 ゝ 提交于 2019-11-29 07:37:24

(Spyder dev here) I'm almost sure your problem is because of a firewall issue. It seems your firewall is too strict and it's blocking all attempts to try to open a port for our purposes.

To avoid blocking the full application while evaluating stuff, we run our python interpreter on a different process than the one Spyder runs on. We communicate with that process using a simple sockets protocol, which opens a new port on your machine and sends data back and forth between the console and Spyder through that port.

That's also the reason why you are not seeing the error on a regular python interpreter: because it doesn't need to open a port to run.

After fumbling with the firewall settings, I couldn't find any that would make spyder work.
Some runs would work, others would not, with the exact same configuration.
I'd rule out the firewall for now.

I noticed that the port that sitecustomize attempts to connect to is not listening.
Setting SPYDER_DEBUG=True before launching spyder gives more details:

Traceback (most recent call last):
  File "P:\Python33\lib\threading.py", line 637, in _bootstrap_inner
    self.run()
  File "P:\Python33\lib\site-packages\spyderlib\widgets\externalshell\introspection.py", line 64, in run
    sock.bind( ("127.0.0.1", self.port) )
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions`

I did a dirty hack by replacing the line:

sock.bind( ("127.0.0.1", self.port) )

by the following:

for loopCount in range(10, -1, -1):
  try:
    sock.bind( ("127.0.0.1", self.port) )
    break
  except OSError:
    if DEBUG:
      logging.debug('Notification server: Bind on port %d failed...' % (self.port))
    if not loopCount:
      raise
    import time
    time.sleep(1)

It seems to work, but this may be more luck than anything else...

Versions:

  • Spyder 2.3.0dev1
  • python 3.3.2 (64 bit)

Following Carlos Cordoba's answer, I did the following (using Ubuntu 15.10):

1-) Disabled the firewall

sudo ufw disable 

2-) Reset spyder and applied default settings:

spyder --reset
spyder --default

3-) Ran Spyder again

spyder

4-) Enabled the firewall

sudo ufw enable

And it is working normally now.

I had this same problem. worked on it for months... the spyder from from the EPEL library for Redhat 7 (Scientific Linux).

Finally figured out I needed a extra package that was not set as a requirement. python-matplotlib

After adding that python package all my problems went away!

Arrrggghhhhh.......!!!!!

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