Repository: spyder-ide/spyder

Issue:
Sitecustomize fails when  current directory has non-ascii chars
## Description

**What steps will reproduce the problem?**
1.  Start Spyder.
2.  Open any *.py file.
3.  Close Spyder.
4.  Open again.

**What is the expected output? What do you see instead?**

The internal python console shows the message "'import sitecustomize' failed"
and stops loading any further. No commands can be executed. After running
spyder --reset
it loads normally until the next startup after I had a file opened. 

**Please provide any additional information below**
## Version and main components
- Spyder Version: 2.3.8 
- Python Version: 2.7.12
- Qt Versions:  4.8.7, PyQt4 (API v2) 4.11.4 on Linux
## Optional dependencies

```
pyflakes >=0.5.0   :  1.1.0 (OK)
pep8 >=0.6         :  None (NOK)
pygments >=1.6     :  2.1 (OK)
IPython >=1.0      :  2.4.1 (OK)
zmq >=2.1.11       :  15.2.0 (OK)
pandas >=0.13.1    :  0.17.1 (OK)
sphinx >=0.6.6     :  1.3.6 (OK)
psutil >=0.3       :  3.4.2 (OK)
rope >=0.9.2       :  0.10.2 (OK)
jedi >=0.8.1;<0.9.0:  0.9.0 (NOK)
matplotlib >=1.0   :  1.5.1 (OK)
sympy >=0.7.3      :  None (NOK)
pylint >=0.25      :  1.5.2 (OK)

```



Discussion:
I found, this only happens, when the working directory at the time of closing spyder has special characters (e.g. 'ß') somewhere in the path.

Thanks for reporting. We'll fix this error after we release Spyder 3.0 :-)

Hi @Dschoni 

I test your problem on my Linux Deepin machine (15.03 64 bits)
1. Open spyder and open *.py file
   ![test 3407 before seleccion_009](https://cloud.githubusercontent.com/assets/5307894/19622079/13b5a98c-9867-11e6-8ca5-a6c3a08ca0b2.png)
2. reopen Spyder
   ![test 3407 after seleccion_009](https://cloud.githubusercontent.com/assets/5307894/19622080/210b3796-9867-11e6-8fed-7c525b7a7b8f.png)

## Spyder & Python Enviroment

> Spyder 3.0.1
> Python 2.7.12 :: Continuum Analytics, Inc.(Anaconda 4.2 64 bits)
> Linux wallas-pc 4.4.0-2-deepin-amd64 #1 SMP Deepin 4.4.6-4 (2016-07-01) x86_64 GNU/Linux

## Dependences

> jedi >=0.8.1     :  0.9.0 (OK)
> matplotlib >=1.0 :  1.5.3 (OK)
> nbconvert >=4.0  :  4.2.0 (OK)
> numpy >=1.7      :  1.11.2 (OK)
> pandas >=0.13.1  :  0.19.0 (OK)
> pep8 >=0.6       :  1.7.0 (OK)
> psutil >=0.3     :  4.3.1 (OK)
> pyflakes >=0.5.0 :  1.3.0 (OK)
> pygments >=2.0   :  2.1.3 (OK)
> pylint >=0.25    :  1.5.4 (OK)
> qtconsole >=4.2.0:  4.2.1 (OK)
> rope >=0.9.4     :  0.9.4 (OK)
> sphinx >=0.6.6   :  1.4.8 (OK)
> sympy >=0.7.3    :  1.0 (OK)

As you can see, you could work with spyder 3.0.1 and our future release (v3.1). Because It solves your issue. @ccordoba12 @goanpeca 

Thanks for the report and contribute with us, to make better Spyder;).

Well no.
The problem is still existing.

Create a folder with non-asci chars (e.g. 'äöüß').
Start spyder.
Set active working directory to that folder.
Close spyder.
Start spyder.
--> Import sitecustomize failed.
(Tested with spyder 3.0.1)

Am 2016-10-22 21:52, schrieb malliwi88:

> Hi @Dschoni [2]
> 
> I test your problem on my Linux Deepin machine (15.03 64 bits)
> 
>   *
> 
> Open spyder and open *.py file
>  [3]
>   *
> 
> reopen Spyder
>  [4]
> 
> SPYDER & PYTHON ENVIROMENT
> 
> > Spyder 3.0.1
> > Python 2.7.12 :: Continuum Analytics, Inc.(Anaconda 4.2 64 bits)
> > Linux wallas-pc 4.4.0-2-deepin-amd64 #1 [1] SMP Deepin 4.4.6-4
> > (2016-07-01) x86_64 GNU/Linux
> 
> DEPENDENCES
> 
> > jedi >=0.8.1 : 0.9.0 (OK)
> > matplotlib >=1.0 : 1.5.3 (OK)
> > nbconvert >=4.0 : 4.2.0 (OK)
> > numpy >=1.7 : 1.11.2 (OK)
> > pandas >=0.13.1 : 0.19.0 (OK)
> > pep8 >=0.6 : 1.7.0 (OK)
> > psutil >=0.3 : 4.3.1 (OK)
> > pyflakes >=0.5.0 : 1.3.0 (OK)
> > pygments >=2.0 : 2.1.3 (OK)
> > pylint >=0.25 : 1.5.4 (OK)
> > qtconsole >=4.2.0: 4.2.1 (OK)
> > rope >=0.9.4 : 0.9.4 (OK)
> > sphinx >=0.6.6 : 1.4.8 (OK)
> > sympy >=0.7.3 : 1.0 (OK)
> 
> As you can see, you could work with spyder 3.0.1 and our future
> release (v3.1). Because It solves your issue. @ccordoba12 [5]
> @goanpeca [6]
> 
> Thanks for the report and contribute with us, to make better Spyder;).
> 
> ## 
> 
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub [7], or mute the
> thread [8].
> 
>   *
> 
> ## Links:
> 
> [1] https://github.com/spyder-ide/spyder/issues/1
> [2] https://github.com/Dschoni
> [3]
> https://cloud.githubusercontent.com/assets/5307894/19622079/13b5a98c-9867-11e6-8ca5-a6c3a08ca0b2.png
> [4]
> https://cloud.githubusercontent.com/assets/5307894/19622080/210b3796-9867-11e6-8fed-7c525b7a7b8f.png
> [5] https://github.com/ccordoba12
> [6] https://github.com/goanpeca
> [7] 
> https://github.com/spyder-ide/spyder/issues/3407#issuecomment-255550041
> [8]
> https://github.com/notifications/unsubscribe-auth/AH3bazIqqUuRsHY6joMGk-xuYIU-7mM7ks5q2mmYgaJpZM4J10sI

@dalthviz, please work on this one. For this you need to create a conda environment with a non-ascii name, install Spyder on it and start it.

Hi @Dschoni, sorry for the late response, can you try to test the problem with Spyder `3.0.2`?. Also, how are you setting up the active working directory, something like this?:

![image](https://cloud.githubusercontent.com/assets/16781833/20867995/0bc55586-ba1f-11e6-9a7a-dd4dd484be43.png)

All the information that you can give us would be greatly appreciated in order to recreate the error that you are having. :)

Hi Daniel,

I have tried reproducing the problem with spyder 3.0.2 and it seems to be (nearly) gone.

I get the following traceback when I change the working directory:


Traceback (most recent call last):
  File "/home/gu32hej/.local/lib/python2.7/site-packages/spyder/plugins/ipythonconsole.py", line 845, in set_current_client_working_directory
    shellwidget.set_cwd(directory)
  File "/home/gu32hej/.local/lib/python2.7/site-packages/spyder/widgets/ipythonconsole/shell.py", line 87, in set_cwd
    "get_ipython().kernel.set_cwd(r'{}')".format(dirname))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in position 14: ordinal not in range(128)


Nevertheless, Spyder DOES start when I close it and open it again!

So, solved for me.


________________________________
Von: Daniel Althviz Moré <notifications@github.com>
Gesendet: Sonntag, 4. Dezember 2016 22:32
An: spyder-ide/spyder
Cc: Schock, Jonathan; Mention
Betreff: Re: [spyder-ide/spyder] Sitecustomize fails when current directory has non-ascii chars (#3407)


Hi @Dschoni<https://github.com/Dschoni>, sorry for the late response, can you try to test the problem with Spyder 3.0.2?. Also, how are you setting up the active working directory, something like this?:

[image]<https://cloud.githubusercontent.com/assets/16781833/20867995/0bc55586-ba1f-11e6-9a7a-dd4dd484be43.png>

All the information that you can give us would be greatly appreciated in order to recreate the error that you are having. :)

-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/3407#issuecomment-264733092>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AH3bawm5rpg0c8kKNxxedrmhcleviQVsks5rEzGGgaJpZM4J10sI>.

Sorry, no. It's back again. I tried with different bundled versions in Anaconda. With a plain Spyder install. 
The error message in terminal is still the same:

'import sitecustomize' failed; use -v for traceback 

Hi again @Dschoni, it's really strange that it worked for you  (at least to close and open Spyder), and then it stopped working. Searching a little bit I think that maybe your problem is about the configuration of  your firewall like in this [post](http://stackoverflow.com/q/17258634). From there are some steps that you can follow:

1. Disable the firewall.
2. Reset Spyder and apply default settings.
3. Run Spyder again.
4. Enable the firewall.

Can you see if following these steps make Spyder work again? I will open a new issue for the new error that you post when you ran Spyder `3.0.2`. Also if you can use the `-v` option to print the traceback and paste it here would be great.

Resolving patch:
diff --git a/spyder/utils/debug.py b/spyder/utils/debug.py
--- a/spyder/utils/debug.py
+++ b/spyder/utils/debug.py
@@ -17,6 +17,8 @@
 import traceback
 import time
 
+from spyder.py3compat import PY2 
+
 
 def log_time(fd):
     timestr = "Logging time: %s" % time.ctime(time.time())
@@ -33,7 +35,10 @@ def log_last_error(fname, context=None):
         print("Context", file=fd)
         print("-------", file=fd)
         print("", file=fd)
-        print(context, file=fd)
+        if PY2:
+            print(u' '.join(context).encode('utf-8').strip(), file=fd)
+        else:
+            print(context, file=fd)
         print("", file=fd)
         print("Traceback", file=fd)
         print("---------", file=fd)
diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py
--- a/spyder/widgets/ipythonconsole/shell.py
+++ b/spyder/widgets/ipythonconsole/shell.py
@@ -83,7 +83,7 @@ def is_running(self):
     def set_cwd(self, dirname):
         """Set shell current working directory."""
         return self.silent_execute(
-                         "get_ipython().kernel.set_cwd(r'{}')".format(dirname))
+            u"get_ipython().kernel.set_cwd(r'{}')".format(dirname))
 
     # --- To handle the banner
     def long_banner(self):


Test patch: