Repository: spyder-ide/spyder

Issue:
Spyder fails to start when trying to set language on Windows
I have install anaconda and trying to open spyder, but i am getting the below error.

Traceback (most recent call last):
File "C:\Users\admin\Anaconda3\Scripts\spyder-script.py", line 6, in
from spyder.app.start import main
File "C:\Users\admin\Anaconda3\lib\site-packages\spyder\app\start.py", line 25, in
from spyder.config.base import get_conf_path, running_in_mac_app
File "C:\Users\admin\Anaconda3\lib\site-packages\spyder\config\base.py", line 362, in
_ = get_translation("spyder")
File "C:\Users\admin\Anaconda3\lib\site-packages\spyder\config\base.py", line 336, in get_translation
os.environ["LANG"] = language # Works on Windows
File "C:\Users\admin\Anaconda3\lib\os.py", line 675, in setitem
self.putenv(key, value)
ValueError: embedded null character

I had install-re-install anaconda couple of times.
tried --reset command too, but nothing is working as of now.

Thanks for the help.


Discussion:
Thanks for reporting. We'll fix this in our next version.
I am not sure if this is related but I am unable to open up the Spyder IDE from Windows. I have uninstalled and installed Anaconda, added the path to environment variables during installation also.
It was working fine 12 hours back. I am not being able to grasp what has happened but found this issue.

The attached image shows the status when I click on spyder within anaconda.
![spyder_errror](https://user-images.githubusercontent.com/11851253/38439721-6633e7b8-39fc-11e8-9b62-0a8a2c3838ff.png)

@shuvayan Not impossible, but unlikely, unless you are getting the error traceback specified above. Please try the steps listed in the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ), specifically the [Basic First Aid](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#basic-first-aid-general-troubleshooting) and [Emergency CPR](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#emergency-cpr-spyder-wont-launch) sections, which resolve the great majority of Spyder installation issues.
HI ! i got the same problem !
spyder --reset / anaconda clean uninstall and reinstall doesn't work ;)

Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Continuum\anaconda3\Scripts\spyder-script.py", line 6, in 
from spyder.app.start import main
File "C:\Users\admin\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\app\start.py", line 25, in 
from spyder.config.base import (get_conf_path, running_in_mac_app,
File "C:\Users\admin\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\config\base.py", line 383, in 
_ = get_translation("spyder")
File "C:\Users\admin\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\config\base.py", line 357, in get_translation
os.environ["LANG"] = language # Works on Windows
File "C:\Users\admin\AppData\Local\Continuum\anaconda3\lib\os.py", line 675, in __setitem__
self.putenv(key, value)
ValueError: embedded null character


Thanks for the information; seems to be a pretty critical error then. Can you try the other steps listed in the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ), specifically the [Basic First Aid](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#basic-first-aid-general-troubleshooting) and [Emergency CPR](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#emergency-cpr-spyder-wont-launch) sections, which resolve the great majority of Spyder installation issues.
I'll take a look at this one.

Resolving patch:
diff --git a/spyder/app/start.py b/spyder/app/start.py
--- a/spyder/app/start.py
+++ b/spyder/app/start.py
@@ -97,8 +97,8 @@ def main():
         os.environ['QT_SCALE_FACTOR'] = ''
         os.environ['QT_SCREEN_SCALE_FACTORS'] = ''
 
-    # Prevent Spyder from crashing in macOS if locale is not defined
     if sys.platform == 'darwin':
+        # Prevent Spyder from crashing in macOS if locale is not defined
         LANG = os.environ.get('LANG')
         LC_ALL = os.environ.get('LC_ALL')
         if bool(LANG) and not bool(LC_ALL):
@@ -110,6 +110,20 @@ def main():
 
         os.environ['LANG'] = LANG
         os.environ['LC_ALL'] = LC_ALL
+    else:
+        # Prevent our kernels to crash when Python fails to identify
+        # the system locale.
+        # Fixes issue 7051.
+        try:
+            from locale import getlocale
+            getlocale()
+        except ValueError:
+            # This can fail on Windows. See issue 6886
+            try:
+                os.environ['LANG'] = 'C'
+                os.environ['LC_ALL'] = 'C'
+            except Exception:
+                pass
 
     if CONF.get('main', 'single_instance') and not options.new_instance \
       and not options.reset_config_files and not running_in_mac_app():
diff --git a/spyder/config/base.py b/spyder/config/base.py
--- a/spyder/config/base.py
+++ b/spyder/config/base.py
@@ -362,13 +362,27 @@ def get_translation(modname, dirname=None):
     """Return translation callback for module *modname*"""
     if dirname is None:
         dirname = modname
+
+    def translate_dumb(x):
+        """Dumb function to not use translations."""
+        if not is_unicode(x):
+            return to_text_string(x, "utf-8")
+        return x
+
     locale_path = get_module_data_path(dirname, relpath="locale",
                                        attr_name='LOCALEPATH')
-    # If LANG is defined in ubuntu, a warning message is displayed, so in unix
-    # systems we define the LANGUAGE variable.
+
+    # If LANG is defined in Ubuntu, a warning message is displayed,
+    # so in Unix systems we define the LANGUAGE variable.
     language = load_lang_conf()
     if os.name == 'nt':
-        os.environ["LANG"] = language      # Works on Windows
+        # Trying to set LANG on Windows can fail when Spyder is
+        # run with admin privileges.
+        # Fixes issue 6886
+        try:
+            os.environ["LANG"] = language      # Works on Windows
+        except Exception:
+            return translate_dumb
     else:
         os.environ["LANGUAGE"] = language  # Works on Linux
  
@@ -385,12 +399,7 @@ def translate_gettext(x):
             else:
                 return to_text_string(y, "utf-8")
         return translate_gettext
-    except IOError as _e:  # analysis:ignore
-        # Not using translations
-        def translate_dumb(x):
-            if not is_unicode(x):
-                return to_text_string(x, "utf-8")
-            return x
+    except Exception:
         return translate_dumb
 
 # Translation callback


Test patch: