Python 嵌入式安装中未设置路径
Python paths not being set on embedded installation
我正在尝试在我的 EspressoBin 单板计算机 (aarch64) 上获取 python3 运行。我已经使用 Marvell 的 openembedded 发行版构建了一个 linux 发行版并包含了 python3
.
问题是 python 的搜索 paths/environment 变量没有被设置。
如果我尝试启动 python3,我得到:
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: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x0000007faef06000 (most recent call first):
Aborted
但是,如果我这样做:
$ export PYTHONHOME="/usr/lib64/python3.5/"
$ export PYTHONPATH="/usr/lib64/python3.5/:/usr/lib64/python3.5/lib-dynload"
$ python3
Python 3.5.1 (default, Jan 14 2019, 23:24:54)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
然后一切都神奇地工作了。
所以问题是... where/how 这些东西通常是被设置的吗?我尝试与 Ubuntu 进行比较,但由于某些原因,这些环境变量根本不存在!我检查了 sys.path 上的文档,它说 sys.path
是从 PYTHONPATH "plus an installation-dependent default" 填充的。所以我猜 Ubuntu 的 "installation-dependent default" 是否预先填充了正确的路径?
我目前的解决方案是将这两个环境变量添加到 /etc/environment
以及 /etc/profile
(用于 ssh 连接),但这似乎是一个 hacky 解决方法,我想这样做对。
在 Python 源代码树中从 Modules/getpath.c 开始是个不错的主意。
哦,还有:好像是版本不匹配? Python是3.6,你给它提供3.5模块?
".../lib64/..."
到 python3.5 的路径看起来不是默认的,
"By default, the libraries are searched in prefix/lib/pythonversion
and exec_prefix/lib/pythonversion
" source
所以我想这可能与此有关,如果您可以重新安装或修改它以安装在 "/lib/"
而不是 "/lib64/"
中,您就不需要设置这两个环境变量.
我正在尝试在我的 EspressoBin 单板计算机 (aarch64) 上获取 python3 运行。我已经使用 Marvell 的 openembedded 发行版构建了一个 linux 发行版并包含了 python3
.
问题是 python 的搜索 paths/environment 变量没有被设置。
如果我尝试启动 python3,我得到:
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: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x0000007faef06000 (most recent call first):
Aborted
但是,如果我这样做:
$ export PYTHONHOME="/usr/lib64/python3.5/"
$ export PYTHONPATH="/usr/lib64/python3.5/:/usr/lib64/python3.5/lib-dynload"
$ python3
Python 3.5.1 (default, Jan 14 2019, 23:24:54)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
然后一切都神奇地工作了。
所以问题是... where/how 这些东西通常是被设置的吗?我尝试与 Ubuntu 进行比较,但由于某些原因,这些环境变量根本不存在!我检查了 sys.path 上的文档,它说 sys.path
是从 PYTHONPATH "plus an installation-dependent default" 填充的。所以我猜 Ubuntu 的 "installation-dependent default" 是否预先填充了正确的路径?
我目前的解决方案是将这两个环境变量添加到 /etc/environment
以及 /etc/profile
(用于 ssh 连接),但这似乎是一个 hacky 解决方法,我想这样做对。
在 Python 源代码树中从 Modules/getpath.c 开始是个不错的主意。
哦,还有:好像是版本不匹配? Python是3.6,你给它提供3.5模块?
".../lib64/..."
到 python3.5 的路径看起来不是默认的,
"By default, the libraries are searched in
prefix/lib/pythonversion
andexec_prefix/lib/pythonversion
" source
所以我想这可能与此有关,如果您可以重新安装或修改它以安装在 "/lib/"
而不是 "/lib64/"
中,您就不需要设置这两个环境变量.