Python 由于LC#U ALL ,使用pytest启动postgres夹具失败;无法更改区域设置错误
几个小时来我一直在挠头,因为我不知道如何调试下面的问题 上下文 我正在一个项目中使用pytest和pytest postgresql来学习TDD pytest-postgres使我能够使用在套接字的/tmp目录中实现postgresql数据库的fixture 这一点过去很有效,如下所述:Python 由于LC#U ALL ,使用pytest启动postgres夹具失败;无法更改区域设置错误,python,postgresql,locale,Python,Postgresql,Locale,几个小时来我一直在挠头,因为我不知道如何调试下面的问题 上下文 我正在一个项目中使用pytest和pytest postgresql来学习TDD pytest-postgres使我能够使用在套接字的/tmp目录中实现postgresql数据库的fixture 这一点过去很有效,如下所述: 医生 本文: 问题 使用该夹具的样本测试会产生以下错误: > raise CalledProcessError(retcode, process.args,
- 医生
- 本文:
> raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['/usr/bin/pg_ctl',
'initdb', '--pgdata', '/tmp/postgresqldata.12836',
'-o', '--username=postgres --auth=trust']' returned non-zero exit status 1.
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
---------------------------- Captured stderr setup -----------------------------
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
initdb: error: invalid locale settings; check LANG and LC_* environment variables
pg_ctl: database system initialization failed
=========================== short test summary info ============================
ERROR tests/adapters/test_orm.py::test_sample - subprocess.CalledProcessError...
=============================== 1 error in 0.11s ===============================
我试过的
- 重置区域设置
- 重新安装postgres
- 重新安装pytest postgres
- 重新安装psycopg2二进制文件
(myproject) [john@linuxbox ~/myproject]$ initdb --pgdata /tmp/postgresqldata.123450 --username=postgres --auth=trust
The files belonging to this database system will be owned by user "john".
This user must also own the server process.
The database cluster will be initialized with locales
COLLATE: fr_FR.UTF-8
CTYPE: fr_FR.UTF-8
MESSAGES: en_US.UTF-8
MONETARY: fr_FR.UTF-8
NUMERIC: fr_FR.UTF-8
TIME: fr_FR.UTF-8
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "french".
Data page checksums are disabled.
creating directory /tmp/postgresqldata.123450 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Paris
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /tmp/postgresqldata.123450 -l logfile start
问题:
- 下面的两个命令是否等效
- 你知道我下一步该去哪里解决这个问题吗
$locale-a的输出
C
en_US.utf8
fr_FR.utf8
POSIX
pytest postgresql位于2.5.1上:
(myproject) [john@linuxbox ~/myproject]$ cat Pipfile.lock | grep pytest-postgresql -A 6
"pytest-postgresql": {
"hashes": [
"sha256:e2a998c85cd7e917c593292182e523d620018887fadde733c932a70c3825b8bd"
],
"index": "pypi",
"version": "==2.5.1"
},
我在Archlinux上使用postgres 12.4
编辑2
我想我找到了原因,我可以从外壳复制错误
在archwiki之后,我做了以下工作:
[postgres@linuxbox ~]$ initdb --locale=C.UTF-8 -E UTF-8 -D /var/lib/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
initdb: invalid locale name "C.UTF-8"
似乎C.UTF-8是特定于Debian的,因此在Archlinux上出现了错误
这一问题似乎密切相关:
pytest postgresql(2.5.1)最新版本的变更日志引用了LC_*环境变量,仅在几天前发布。如果尚未安装,请务必使用最新版本进行检查。确保系统中安装了C.UTF-8区域设置(运行区域设置命令-请参阅)。
(myproject) [john@linuxbox ~/myproject]$ cat Pipfile.lock | grep pytest-postgresql -A 6
"pytest-postgresql": {
"hashes": [
"sha256:e2a998c85cd7e917c593292182e523d620018887fadde733c932a70c3825b8bd"
],
"index": "pypi",
"version": "==2.5.1"
},
[postgres@linuxbox ~]$ initdb --locale=C.UTF-8 -E UTF-8 -D /var/lib/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
initdb: invalid locale name "C.UTF-8"