gpt4 book ai didi

python - 为什么 cqlsh 失败并出现 LookupError : unknown encoding?

转载 作者:行者123 更新时间:2023-11-28 21:53:32 24 4
gpt4 key购买 nike

我刚刚在 Mac OS X 10.9.4 上使用 brew 安装了 Cassandra:

➜  ~  brew info cassandra
cassandra: stable 2.1.0
http://cassandra.apache.org
/usr/local/Cellar/cassandra/2.0.9 (3466 files, 79M) *
Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/cassandra.rb
==> Caveats
If you plan to use the CQL shell (cqlsh), you will need the Python CQL library
installed. Since Homebrew prefers using pip for Python packages, you can
install that using:

pip install cql

To have launchd start cassandra at login:
ln -sfv /usr/local/opt/cassandra/*.plist ~/Library/LaunchAgents
Then to load cassandra now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.cassandra.plist
➜ ~ uname -a
Darwin xxx 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

按照上面信息消息中的建议,为了安装 cql,我执行了 sudo easy_install pip,然后是 pip install cql

安装软件后,在执行 cqlsh 时我遇到了错误:

➜  ~  cqlsh
Traceback (most recent call last):
File "/usr/local/bin/cqlsh", line 2084, in <module>
main(*read_options(sys.argv[1:], os.environ))
File "/usr/local/bin/cqlsh", line 2067, in main
single_statement=options.execute)
File "/usr/local/bin/cqlsh", line 509, in __init__
self.output_codec = codecs.lookup(encoding)
LookupError: unknown encoding:

我该如何解决?

最佳答案

经过一些谷歌搜索和调试后,事实证明对 locale.getpreferredencoding() 的调用需要正确的 LC_ALL,如 22.2. locale — Internationalization services 中所述。 :

To maintain compatibility with other platforms, not only the LANG variable is tested, but a list of variables given as envvars parameter. The first found to be defined will be used. envvars defaults to the search path used in GNU gettext; it must always contain the variable name LANG. The GNU gettext search path contains 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', and 'LANG', in that order.

在我的系统上 LC_ALL 被设置为 pl_PL:

➜  ~  echo $LC_ALL
pl_PL

LC_ALL 更改为 plpl_pl.utf-8 后,Cassandra shell cqlsh 启动正常:

➜  ~  export LC_ALL=pl_pl.utf-8
➜ ~ cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.9 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>

查看主题 Problem start cqlsh on OSX - Lion用于检查语言环境的示例 Python 应用程序:

python -c 'import locale, codecs; encoding = locale.getpreferredencoding(); print encoding; print codecs.lookup(encoding)'

一旦运行正常,问题就可以认为已经解决了。

关于python - 为什么 cqlsh 失败并出现 LookupError : unknown encoding?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com