gpt4 book ai didi

linux - 静态构建的 python3.7 在移出构建文件夹时停止工作

转载 作者:太空狗 更新时间:2023-10-29 12:39:15 25 4
gpt4 key购买 nike

我想使用静态 python 解释器在严格管理的服务器上运行。到目前为止,我已经构建了解释器,但我只能在构建目录中使用它。

如果我尝试复制它并使用副本,它会停止工作,并因以下错误而失败-

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped) ./../python

我看过this question ,并使用第一个答案中建议的修复解决了 prefix 和 exec_prefix 问题,但没有解决“无法获取语言环境编码”问题。我真的找不到与我相关的解决方案。

顺便说一句,这与 virtualenv 无关,echo $PYTHONPATHecho $PYTHONHOME 当我在任何 virtualenvs 之外尝试时都返回一个空字符串。当它在构建目录中时,我可以很好地运行静态二进制文件。

这是一个例子-

~/Python-3.7.2$ ./python
Python 3.7.2 (default, Jan 26 2019, 19:14:39)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
~/Python-3.7.2$ cp python ..
~/Python-3.7.2$ ./../python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped) ./../python

~/Python-3.7.2$ export PYTHONHOME=/usr/local
~/Python-3.7.2$ ./../python
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000000011b1900 (most recent call first):
zsh: abort (core dumped) ./../python

最佳答案

好的,我已经解决了我的问题。这是由在 configure 中设置 --prefix 选项引起的。如果你在运行时没有指定正确的前缀,python 将不知道它的标准库在哪里。

要从任何地方使用 python 二进制文件,您应该手动指定 PYTHONHOMEPYTHONPATH 环境变量,或者将二进制文件保存在运行配置时指定的目录中.

例如,如果您使用 --prefix=/home/blah/python_src 运行配置,那么您必须保留在那里构建的二进制文件或执行类似 export PYTHONHOME=/home/的操作blah/python_src 在使用它之前。

关于linux - 静态构建的 python3.7 在移出构建文件夹时停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54381169/

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