Search code examples
pythonlinuxpython-3.xopenembeddedlinux-distro

Python paths not being set on embedded installation


I am trying to get python3 running on my EspressoBin single board computer (aarch64). I have built a linux distribution using Marvell's openembedded distribution and included python3.

The problem is that python's search paths/environment variables are not being set.

If I try to start python3, I get:

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

If, however, I do:

$ 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.
>>>

Then everything magically works.

So the question is... where/how are these things normally being set? I tried comparing to Ubuntu, but for some reason those environment variables aren't even present at all! I checked the docs on sys.path and it says that sys.path is populated from PYTHONPATH, "plus an installation-dependent default". So I'm guessing Ubuntu's "installation-dependent default" has the correct paths pre-populated?

My current solution is to just add those two environment variables to /etc/environment, as well as /etc/profile (for ssh connections), but this seems like a hacky workaround and I want to do it right.


Solution

  • The path ".../lib64/..." to python3.5 does not look default,

    "By default, the libraries are searched in prefix/lib/pythonversion and exec_prefix/lib/pythonversion " source

    So I guess that it could be related to that and if you could reinstall or modify it to be installed in "/lib/" instead of "/lib64/" you wouldn't need to set those two environment variables.