4

I have compiled from the sources and installed python 3.6 and when I type python3.6 in the console I get:

Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 3.6.1rc1+ (default, Mar 11 2017, 15:01:24) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I have read (here https://docs.python.org/3/using/cmdline.html#environment-variables) that in general I don't need set PYTHONHOME variable (and I don't want set it).

I have installed also other python version (2.7 and 3.4) without problem.

I understand by platform dependent libraries the shared object libraries that loads python like these:

$ ls /usr/lib/python3.6/ | grep .so
array.cpython-36m-arm-linux-gnueabihf.so
_asyncio.cpython-36m-arm-linux-gnueabihf.so
audioop.cpython-36m-arm-linux-gnueabihf.so
binascii.cpython-36m-arm-linux-gnueabihf.so
_bisect.cpython-36m-arm-linux-gnueabihf.so
_blake2.cpython-36m-arm-linux-gnueabihf.so
cmath.cpython-36m-arm-linux-gnueabihf.so
_codecs_cn.cpython-36m-arm-linux-gnueabihf.so
_codecs_hk.cpython-36m-arm-linux-gnueabihf.so
_codecs_iso2022.cpython-36m-arm-linux-gnueabihf.so
_codecs_jp.cpython-36m-arm-linux-gnueabihf.so
_codecs_kr.cpython-36m-arm-linux-gnueabihf.so
_codecs_tw.cpython-36m-arm-linux-gnueabihf.so
_crypt.cpython-36m-arm-linux-gnueabihf.so
_csv.cpython-36m-arm-linux-gnueabihf.so
_ctypes.cpython-36m-arm-linux-gnueabihf.so
_ctypes_test.cpython-36m-arm-linux-gnueabihf.so
cv2.cpython-36m-arm-linux-gnueabihf.so
_datetime.cpython-36m-arm-linux-gnueabihf.so
_decimal.cpython-36m-arm-linux-gnueabihf.so
_elementtree.cpython-36m-arm-linux-gnueabihf.so
fcntl.cpython-36m-arm-linux-gnueabihf.so
grp.cpython-36m-arm-linux-gnueabihf.so
_hashlib.cpython-36m-arm-linux-gnueabihf.so
_heapq.cpython-36m-arm-linux-gnueabihf.so
json
_json.cpython-36m-arm-linux-gnueabihf.so
_lsprof.cpython-36m-arm-linux-gnueabihf.so
_lzma.cpython-36m-arm-linux-gnueabihf.so
math.cpython-36m-arm-linux-gnueabihf.so
_md5.cpython-36m-arm-linux-gnueabihf.so
mmap.cpython-36m-arm-linux-gnueabihf.so
_multibytecodec.cpython-36m-arm-linux-gnueabihf.so
_multiprocessing.cpython-36m-arm-linux-gnueabihf.so
nis.cpython-36m-arm-linux-gnueabihf.so
_opcode.cpython-36m-arm-linux-gnueabihf.so
ossaudiodev.cpython-36m-arm-linux-gnueabihf.so
parser.cpython-36m-arm-linux-gnueabihf.so
_pickle.cpython-36m-arm-linux-gnueabihf.so
_posixsubprocess.cpython-36m-arm-linux-gnueabihf.so
pyexpat.cpython-36m-arm-linux-gnueabihf.so
_random.cpython-36m-arm-linux-gnueabihf.so
resource.cpython-36m-arm-linux-gnueabihf.so
select.cpython-36m-arm-linux-gnueabihf.so
_sha1.cpython-36m-arm-linux-gnueabihf.so
_sha256.cpython-36m-arm-linux-gnueabihf.so
_sha3.cpython-36m-arm-linux-gnueabihf.so
_sha512.cpython-36m-arm-linux-gnueabihf.so
_socket.cpython-36m-arm-linux-gnueabihf.so
spwd.cpython-36m-arm-linux-gnueabihf.so
_ssl.cpython-36m-arm-linux-gnueabihf.so
_struct.cpython-36m-arm-linux-gnueabihf.so
syslog.cpython-36m-arm-linux-gnueabihf.so
termios.cpython-36m-arm-linux-gnueabihf.so
_testbuffer.cpython-36m-arm-linux-gnueabihf.so
_testcapi.cpython-36m-arm-linux-gnueabihf.so
_testimportmultiple.cpython-36m-arm-linux-gnueabihf.so
_testmultiphase.cpython-36m-arm-linux-gnueabihf.so
unicodedata.cpython-36m-arm-linux-gnueabihf.so
xxlimited.cpython-36m-arm-linux-gnueabihf.so
zlib.cpython-36m-arm-linux-gnueabihf.so

If I print sys.path:

$ python3.6
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 3.6.1rc1+ (default, Mar 11 2017, 15:01:24) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/lib-dynload', '/home/pi/.local/lib/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
>>>

you can see that python are searching in that directory.

When I try to import any dependent library, such as math.cpython-36m-arm-linux-gnueabihf.so its works.

$ python3.6
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 3.6.1rc1+ (default, Mar 11 2017, 15:01:24) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> dir(math)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>> math.cos(2)
-0.4161468365471424

So, the question is what means platform dependent libraries and where is its default path?

RdlP
  • 1,366
  • 5
  • 25
  • 45

2 Answers2

3

I often encounter this building Python from source on OpenSuse. After

./configure
make
sudo make altinstall

the interpreter produces this output when invoked

$ python3.9
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 3.9.0a6 (default, Apr 29 2020, 07:38:01) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Module readline not available.

I find found a comment in a Python bug report that suggests symlinking lib-dynload from lib to lib64, and this fixes the problem for me.

$ sudo ln -s /usr/local/lib64/python3.9/lib-dynload /usr/local/lib/python3.9/lib-dynload

According to this bug report this problem is fixed for 3.9, but it wasn't for me at 3.9.0a6. It may be that it is only fixed for distro installations (or my system is messed up, which is also quite possible, it's been through a decade of OpenSuse upgrades).

In fact, after finally buying a new computer, it seems I can build Python from source on OpenSuse without needing to add the symbolic link.

This answer in the linked duplicate has the correct solution for building from source.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
1

If Python 3.6 successfully compiled add export PYTHONHOME=/usr/local to your .bashrc file. Or edit the prefix and exec_prefix on sysconfig file but the former is a simpler solution.

Adriano
  • 750
  • 5
  • 9