Repository: spyder-ide/spyder

Issue:
Spyder crashes on Windows because of non-ascii chars in working directory
_From [fausto.b...@gmail.com](https://code.google.com/u/118270873143688293702/) on 2014-12-10T12:23:51Z_

Please note that reporting bugs from Spyder's help menu ("?" > "Report
issue...") will fill version details for Spyder, Python and Qt in this description for you. 

What steps will reproduce the problem?
1.  I simply run Spyder from its shortcut 2. 3. 

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

 Instead of Spyder I get the attached crash window (PNG file).  When I close it, Windows tells me that "pythonw.exe has stopped working" and offers to check online for a solution or to close the program. What version of the product are you using? On what operating system? Windows 7-64, Python 2.7.8-64, Spyder 2.3.2 

Please provide any additional information below

. The crash window advises me to run "python spyder --reset".  If I do that Spyder works for a while, but minimal changes in its Preferences make it crash again.

If I try to reinstall Spyder from the installer it says that Python 2.7 couldn't be found in the Registry, but it is there because Python works in interactive mode.

**Attachment:** [spyder.png](http://code.google.com/p/spyderlib/issues/detail?id=2081)

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=2081_



Discussion:
_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-12-12T13:46:19Z_

Couple of questions:
1. What are the changes you try to do in Preferences before Spyder crashes again?
2. Are you using a Windows account with non-ascii characters? like á, é or something like that?

**Labels:** MS-v2.3.3 Cat-Settings  

_From [fausto.b...@gmail.com](https://code.google.com/u/118270873143688293702/) on 2014-12-15T05:13:53Z_

Hello CCordoba12,

Answers to your questions:
1. Simple things such as changing the the folder where Spyder should point to by default to find source files.
2. Even though I use special characters (Brazilian Portuguese keyboard with special characters like á, é, etc) the /account/ I use has none of those.  It's called "fausto", simple like that.  My scripts usually don't have special characters, either (I avoid them).

I've been happily using Spyder in my work (Windows machine) and home (Ubuntu) over the last year, simply love it, it beats other IDEs hands down, but I've gotten this issue lately.  Don't know what to do, because nothing has changed on my system.  This is a Windows-only issue I'm afraid.  At home, where I run Ubuntu, Spyder is working beautifully as ever.

Thanks for your reply.

Fausto

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2014-12-15T09:13:08Z_

Thanks for the answers Fausto and I'm glad to hear you're enjoying Spyder.

Could you please describe exactly what preference are you changing and post here the directory name you are using for source files?

I think this problem is related to some difficulties we have to handle option values with non-ascii characters in Python 2. Our Python 3 version should work without problems though :-)

_From [fausto.b...@gmail.com](https://code.google.com/u/118270873143688293702/) on 2014-12-15T10:24:26Z_

Hello,

I observed that the crash usually happens after I try to change:

Tools/Preferences/Global working directory/Startup/the following directory:

and

Tools/Preferences/Run/Working directory/the following directory:

But those may not be the root of the actual problem, it's just my guess.  I simply observed that Spyder crashed a couple of times after my trying to tweak those values.

The non-ascii characters may not be the ones to blame, either.  My computer, keyboard, regional language configuration, etc, etc, have always been the same since I installed Spyder for the 1st time.  Why only now it began to crash?

If there's any other log/config file I might send, please let me know.

As for Python 3, I for one would like to keep using Python 2.7.  Will that be possible with the new version?  Maybe the time to move to another IDE has come
(but I will certainly keep using Spyder on Ubuntu).

Fausto

_From [dan.mcc...@gmail.com](https://code.google.com/u/111161167412309728311/) on 2014-12-19T19:30:57Z_

I just installed spyder on windows too (normally use Linux) and here is how I solved this issue:
1. The crash (in my case) was an unmet dependency for jinja2. I'm using miniconda, so "conda install jinja2" got the dependency met (though pip should also work)
2. the start menu shortcuts that were getting created by "conda install spyder" were creating two problems: (a) the path name in the shortcut had a forward slash instead of backward slash just before the filename (the rest of the path was correct), and (b) it was trying to start spyder in $DOCUMENTS/Python scripts, which is a directory that doesn't exist (and in my case, resides on a different drive than C:/, which can also sometimes cause problems).  I suggest starting it in C:/Users/$USER

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2015-01-01T14:30:21Z_

Thanks @-Dan for the solution but I think the problem is a bit different in this case.

@-Fausto Spyder will continue to work with Python 2 and 3 for the foreseeable future. This is just a bug.

**Summary:** Spyder crashes on Windows because of non-ascii chars in working directory  <span class="oldvalue"> (was: Spyder crashes on start-up.) </span>  

_From [ccordoba12](https://code.google.com/u/ccordoba12/) on 2015-01-10T11:11:10Z_

I can't reproduce this error, sorry.

@-Fausto: could you try to start Spyder from a terminal (i.e. cmd.exe) and post here the error you see there? Thanks

**Labels:** -MS-v2.3.3 MS-v2.3.4  

I have nearly the same issue (Anaconda 2.1 distribution, Windows 7 32 bit, Python 2.7.4, Spyder 2.3.1).
The user name on my PC and thus HOMEPATH directory both contain non-ascii characters (Russian).
This caused issues with python itself in Anaconda which I could workaround.
However, when I start Spyder from cmd.exe (or in any other way), the splash window appears and soon (after 1-2 sec) Spyder crashes, cmd.exe window is closed, I don't see any errors reported.
I can change user name at home, but for my university PCs this is not an option.
spyder --reset doesn't help.

I found a workaround: unset HOMEPATH and USERPROFILE environment variables and launch spyder. My .bat file looks like this:
set HOMEPATH=
set USERPROFILE=
C:\Anaconda\Scripts\spyder.exe

After looking at the code I have identified several changes to both Anaconda distribution and Spyder which make it launch fine. However, I'm not sure that my changes are compatible with other environments.

I have created a patch py(w) with Tkinter GUI which does the job. I also could bundle it into exe via py2exe and compress to single self-extracting exe via WinRAR to be 100% independent of python issues.

py(w) file is here: 
http://almalabs.ru/os/wp-content/uploads/2015/03/patch-Anaconda-2.1.0-Windows-gui-en.pyw

exe file is here:
http://almalabs.ru/os/wp-content/uploads/2015/03/patch-Anaconda-2.1.0-Windows-gui-en.sfx.exe

@vasily-smirnov thanks for your interest in helping us solve this problem. Your patch seems to touch parts of the Python `os` module, that we really can't touch.

Is it possible for you to try to come up with a solution that only touches Spyder code? Also, please open a pull request for this :-)

Ok, thanks for the input regarding os module.
I will open a pull request for spyderlib\userconfig.py only - the changes seem failsafe and worth doing.

Thanks a lot Vasily! Really waiting for it :-)

El 02/03/15 a las 02:31, vasily-smirnov escribió:

> Ok, thanks for the input regarding os module.
> I will open a pull request for spyderlib\userconfig.py only - the 
> changes seem failsafe and worth doing.
> 
> —
> Reply to this email directly or view it on GitHub 
> https://github.com/spyder-ide/spyder/issues/2081#issuecomment-76668887.


Resolving patch:
diff --git a/spyderlib/userconfig.py b/spyderlib/userconfig.py
--- a/spyderlib/userconfig.py
+++ b/spyderlib/userconfig.py
@@ -48,6 +48,8 @@
 from spyderlib.py3compat import configparser as cp
 from spyderlib.py3compat import PY2, is_text_string, to_text_string
 
+if PY2:
+    import codecs
 
 #==============================================================================
 # Auxiliary classes
@@ -113,7 +115,7 @@ def _save(self):
         def _write_file(fname):
             if PY2:
                 # Python 2
-                with open(fname, 'w') as configfile:
+                with codecs.open(fname, 'w', encoding='utf-8') as configfile:
                     self._write(configfile)
             else:
                 # Python 3
@@ -251,7 +253,13 @@ def load_from_ini(self):
         try:
             if PY2:
                 # Python 2
-                self.read(self.filename())
+                fname = self.filename()
+                if osp.isfile(fname):
+                    try:
+                        with codecs.open(fname, encoding='utf-8') as configfile:
+                            self.readfp(configfile)
+                    except IOError:
+                        print("Failed reading file", fname)
             else:
                 # Python 3
                 self.read(self.filename(), encoding='utf-8')


Test patch: