0

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.

Gillespie
  • 5,780
  • 3
  • 32
  • 54

2 Answers2

2

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.

Anton Bärwald
  • 798
  • 1
  • 6
  • 15
  • Indeed, adding a softlink `/usr/lib/python3.5 -> /usr/lib64/python3.5` seems to fix the issue (I'm able to eliminate the environment variables). `lib64` must be some installation prefix openembedded is choosing because of the architecture `aarch64`... I'll have to look into it. Thanks! – Gillespie Feb 21 '19 at 16:25
  • Confirmed that my `${libdir}` is being change from the default `lib` to `lib64` because of the architecture `aarch64` – Gillespie Feb 21 '19 at 16:43
  • Solution is to either modify the python recipe, modify local.conf, or add softlink in a `ROOTFS_POSTPROCESS_COMMAND` – Gillespie Feb 21 '19 at 16:49
0

Starting with Modules/getpath.c in Python source tree would not be a bad idea.

Oh, and: there seems to be a version mismatch? Python is 3.6, yet you provide 3.5 modules to it?