我在以其他用户身份运行 python 时遇到了问题。我查看了其他帖子,但似乎我的问题有点不同,因为解决方案不起作用。我以“yuri”身份登录并以“clickhouse”用户身份启动 ClickHouse。我想在 ClickHouse 中运行 UDF,因此它与以“clickhouse”用户身份运行 python 程序类似。在这里我遇到了查找 python 模块的问题。到目前为止,我尝试了以下方法:
当以 sudo -u 'yuri' 身份运行时,一切正常:
$ sudo -u 'yuri' /usr/bin/python3 -c "import sys; sys.path = ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/yuri/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages']; print(sys.path);import sentence_transformers; print('done')" ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/yuri/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages'] done
当以 sudo -u 'clickhouse' 身份运行时,尽管定义了 sys.path,但找不到模块:
sudo -u 'clickhouse' /usr/bin/python3 -c "import sys; sys.path = ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/yuri/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages']; print(sys.path);import sentence_transformers; print('done')" ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/yuri/.local/lib/python3.10/site-packages', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages'] Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'sentence_transformers'
我已将包含模块的目录的权限(递归)设置为 777,甚至还将所有者更改为“clickhouse”:
~/.local/lib/python3.10/site-packages$ ls -ld */
drwxrwxrwx 9 clickhouse yuri 4096 Oct 13 16:01 sentence_transformers/
drwxrwxrwx 2 clickhouse yuri 4096 Oct 13 16:01 sentence_transformers-2.2.2.dist-info/
此时我真的很迷茫,我还应该做什么?运行程序时会创建“clickhouse”用户,而不是合适的用户。
$ groups clickhouse
clickhouse : clickhouse
谢谢