Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'import sitecustomize' failed upon starting spyder

I am trying to install python. Or actually, have installed and deinstalled it a few times now. I am using pythonxy with the spyder IDE (i am used to matlab is why i want to use spyder). The 3.3.2 python would not even start with spyder on my win8 machine, so now I have the 2.7 version installed.

Spyder starts up now, but upon startup I get `'import sitecustomize' failed? in my console and python wont execute any commands I enter. After the error the startupscript keeps on going forever without doing anything and I cant do anything either anymore. The error tells me to start python with -v appendix, output below.

I have googled this error which gave me two possible solutions: i should edit python.rb https://github.com/mxcl/homebrew/commit/10ba101c323f98118b427f291e15abc5b3732991 or i should apply this (attachment in last post there) to sitecustomize https://code.google.com/p/spyderlib/issues/detail?id=771

Applying the diff file did not help and as mata explains below the .rb file is used during install, so not applicable to my problem.

So my question: Does anybody know how to fix this bug from experience?

The error:

'import sitecustomize' failed; use -v for traceback
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

The traceback:

C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc matches C:\Python27\lib\site-packages\spyderlib\pil_patch.py

import spyderlib.pil_patch # precompiled from C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc

Traceback (most recent call last):

  File "C:\Python27\lib\site.py", line 498, in execsitecustomize
    import sitecustomize

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 174, in <module>

    os.environ["SPYDER_AR_STATE"].lower() == "true")
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\monitor.py", line 146, in __init__

    self.n_request.connect( (host, notification_port) )
  File "C:\Python27\lib\socket.py", line 224, in meth

    return getattr(self._sock,name)(*args)

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
like image 711
Leo Avatar asked Jun 23 '13 07:06

Leo


4 Answers

(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.

like image 164
Carlos Cordoba Avatar answered Nov 20 '22 02:11

Carlos Cordoba


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.

like image 39
Carlos Souza Avatar answered Nov 20 '22 00:11

Carlos Souza


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)
like image 2
Laurent Doré Avatar answered Nov 20 '22 00:11

Laurent Doré


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.......!!!!!

like image 1
anthony Avatar answered Nov 20 '22 01:11

anthony