Repository: psychopy/psychopy

Issue:
gui import from psychopy not woriking
Hi all,

im trying to run a psychopy script from terminal but I get this error:

Traceback (most recent call last):
  File "nf_test_lastrun.py", line 11, in <module>
    from psychopy import visual, core, data, event, logging, sound, gui
  File "/Library/Python/2.7/site-packages/PsychoPy-1.81.00-py2.7.egg/psychopy/gui.py", line 11, in <module>
    from psychopy.app import localization
  File "/Library/Python/2.7/site-packages/PsychoPy-1.81.00-py2.7.egg/psychopy/app/localization/**init**.py", line 89, in <module>
    languageID, lang = getID()
  File "/Library/Python/2.7/site-packages/PsychoPy-1.81.00-py2.7.egg/psychopy/app/localization/**init**.py", line 78, in getID
    val = codeFromWxId[wx.LANGUAGE_DEFAULT]
KeyError: 0

when I open python and try to import from python, all work but gui.

any suggestions
thanks
clemens



Discussion:
As a work-around, try setting your language explicitly (in preferences, locale).

To help debug, what OS and version? And what output do you get if you do this:

```
>>> import wx
>>> wx.version()
>>> wx.Locale().GetLanguageInfo(0).CanonicalName
```

Hi,

I am getting same error in Windows-7 64-bit
Here is the output of the commands you suggested to look into. 

> > > import wx
> > > wx.version()
> > > '2.8.12.0 (msw-unicode)'
> > > wx.Locale().GetLanguageInfo(0).CanonicalName
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in <module>
> > > AttributeError: 'NoneType' object has no attribute 'CanonicalName'

Thanks.

The version PsychoPy-1.80.03 is working on my system.

Probably the windows standalone installation getting some problem with the system environment variable. After fresh installation I can not open my system's environment variable tab. It needs a restart.
Upto 1.80.07 all are running. Problem starts from 1.81.00. 

I am facing similar issue when I try to open Psychopy 1.81 on Windows 7 64 bit. I am not able to see the splash screen (refer to logs below). I am using 1.80 on the same machine without any issues.

\PsychoPy-1.81.02\PsychoPy-1.81.02>python "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.81.00-py2.7.egg\psychopy\app\psychopyApp.py"
Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.81.00-py2.7.egg\psychopy\app\psychopyApp.py", line 48, in <module>
    app = PsychoPyApp(0, showSplash=showSplash)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.81.00-py2.7.egg\psychopy\app_psychopyApp.py", line 76, in **init**
    self.onInit(**kwargs)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.81.00-py2.7.egg\psychopy\app_psychopyApp.py", line 90, in onInit
    from psychopy.app import localization  # needed by splash screen
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.81.00-py2.7.egg\psychopy\app\localization__init__.py", line 89, in <module>
    languageID, lang = getID()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.81.00-py2.7.egg\psychopy\app\localization__init__.py", line 78, in getID
    val = codeFromWxId[wx.LANGUAGE_DEFAULT]
KeyError: 0


Resolving patch:
diff --git a/psychopy/app/localization/__init__.py b/psychopy/app/localization/__init__.py
--- a/psychopy/app/localization/__init__.py
+++ b/psychopy/app/localization/__init__.py
@@ -31,13 +31,10 @@
 
 # Get a dict of locale aliases from wx.Locale() -- same cross-platform (Win 7, Mac 10.9)
 locale = wx.Locale()
-aliases = {}
-wxIdFromCode = {}  # int: 0, 2-229
-codeFromWxId = {}  # used in directory names e.g. ja_JP; never JPN ala Windows
-winmap = {}  # get windows 3-letter code (=val) from canonical form (=key); use only for setting locale (non-wx)
-locname = {}  # descriptive name, if available; 5-letter code if not
-reverseMap = {}
-
+aliases = {u'English (U.S.)': 'en_US'}
+# set defaults because locale.GetLanguageInfo(0) can return None on some systems:
+wxIdFromCode = {'en_US': wx.LANGUAGE_DEFAULT}  # int: 0 default, 2-229
+codeFromWxId = {wx.LANGUAGE_DEFAULT: 'en_US'}  # used in directory names e.g. ja_JP; never JPN ala Windows
 for i in range(230):
     info = locale.GetLanguageInfo(i)
     if info:
@@ -45,6 +42,10 @@
         wxIdFromCode[info.CanonicalName] = i
         codeFromWxId[i] = info.CanonicalName
 
+# read all known mappings cross-platform from a file:
+winmap = {'en_US': 'ENU'}  # get windows 3-letter code (=val) from canonical form (=key); use only for setting locale (non-wx)
+locname = {'en_US': u'English (U.S.)'}  # descriptive name, if available; 5-letter code if not
+reverseMap = {u'English (U.S.)': 'en_US'}
 mappings = os.path.join(os.path.dirname(__file__), 'mappings.txt')
 for line in codecs.open(mappings, 'rU', 'utf8').readlines():
     try:


Test patch: