如何設置在OS X Mountain Lion中運行哪些應用程序的默認區域設置(LANG,LC_ALL = en_US.UTF-8)?如何在OSX Mountain Lion中設置應用程序包的默認區域設置
我想運行一個Python程序打包到.app與py2app。當通過在其上的雙擊,代碼段中運行該應用
import locale
print locale.getlocale()
返回(無,無)
然而,通過執行
opensesame.app/Contents/MacOS/opensesame
所述的getLocale運行從終端應用程序時( )功能正確返回(en_US,UTF-8)
(由於終端具有正確的環境設置)
我到目前爲止因爲發現應用程序在雙擊時運行在不同於它們從終端運行時的環境中,所以現在我試圖設置應用程序的默認編碼變量。
我試圖找到我的建議: How can you get the system default language/locale, in a py2app packaged Python app on Mac OS X? 跟着上的指示:http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPInternational/Articles/ChoosingLocalizations.html
我已經在應用程序中添加這兩種CFBundleLocalizations和LSEnvironment鍵的Info.plist(貼在下面)捆綁,但getlocale()函數保持回調(無,無)
任何人都可以告訴我爲OS X應用程序正確設置這些變量,以便Python選取這些變量嗎?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>opensesame</string>
<key>CFBundleExecutable</key>
<string>opensesame</string>
<key>CFBundleIconFile</key>
<string>opensesame.icns</string>
<key>CFBundleIdentifier</key>
<string>org.pythonmac.unspecified.opensesame</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>opensesame</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.0.0</string>
<key>CFBundleLocalizations</key>
<string>en_US.UTF-8</string>
<key>LSHasLocalizedDisplayName</key>
<false/>
<key>NSAppleScriptEnabled</key>
<false/>
<key>NSHumanReadableCopyright</key>
<string>Copyright not specified</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSEnvironment</key>
<dict>
<key>LANG</key>
<string>en_US.UTF-8</string>
<key>LC_ALL</key>
<string>en_US.UTF-8</string>
</dict>
<key>PyMainFileNames</key>
<array>
<string>__boot__</string>
</array>
<key>PyOptions</key>
<dict>
<key>alias</key>
<false/>
<key>argv_emulation</key>
<false/>
<key>emulate_shell_environment</key>
<false/>
<key>no_chdir</key>
<false/>
<key>prefer_ppc</key>
<false/>
<key>site_packages</key>
<false/>
<key>use_pythonpath</key>
<false/>
</dict>
<key>PyResourcePackages</key>
<array/>
<key>PyRuntimeLocations</key>
<array>
<string>@executable_path/../Frameworks/Python.framework/Versions/2.7/Python</string>
</array>
<key>PythonInfoDict</key>
<dict>
<key>PythonExecutable</key>
<string>@executable_path/../Frameworks/Python.framework/Versions/2.7/Python</string>
<key>PythonLongVersion</key>
<string>2.7.3 (default, Mar 19 2013, 18:26:22)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)]</string>
<key>PythonShortVersion</key>
<string>2.7</string>
<key>py2app</key>
<dict>
<key>alias</key>
<false/>
<key>template</key>
<string>app</string>
<key>version</key>
<string>0.7.3</string>
</dict>
</dict>
</dict>
</plist>
你使用哪個版本的py2app? LSEnvironment中的其他環境變量是否在os.environ中結束?最近版本的py2app在環境中覆蓋LC_ALL,以確保py3k正確初始化並且IIRC我不會在之後恢復以前的LC_ALL值。 – 2013-03-26 15:07:28
我已經使用了0.7.3版本,我相信它是最新版本。 – 2013-03-26 15:18:13