【问题标题】:Could not find platform dependent libraries <exec_prefix> in python 3.6.1在 python 3.6.1 中找不到平台相关库 <exec_prefix>
【发布时间】:2017-03-14 17:19:51
【问题描述】:

我已经从源代码编译并安装了 python 3.6,当我在控制台中键入 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.
>>> 

我已阅读(此处为 https://docs.python.org/3/using/cmdline.html#environment-variables),通常我不需要设置 PYTHONHOME 变量(我不想设置它)。

我还安装了其他 python 版本(2.7 和 3.4)没有问题。

我通过platform dependent libraries 了解加载 python 的共享对象库,如下所示:

$ 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

如果我打印 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']
>>>

你可以看到python正在那个目录中搜索。

当我尝试导入任何依赖库时,例如 math.cpython-36m-arm-linux-gnueabihf.so 它的作品。

$ 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

那么,问题是platform dependent libraries 是什么意思,它的默认路径在哪里?

【问题讨论】:

    标签: python linux python-3.x ipython


    【解决方案1】:

    我经常在 OpenSuse 上遇到这种从源代码构建 Python。之后

    ./configure
    make
    sudo make altinstall
    

    解释器在调用时产生此输出

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

    我在 Python 错误报告中发现了一个 comment,它建议将 lib-dynloadlib 符号链接到 lib64,这解决了我的问题。

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

    根据bug report,这个问题在 3.9 中已修复,但在 3.9.0a6 中不适用于我。可能是它只针对发行版安装修复(或者我的系统搞砸了,这也很有可能,它已经经历了十年的 OpenSuse 升级)。

    【讨论】:

    • 我仍然需要这个解决方法来在那个旧盒子上构建 3.10。
    【解决方案2】:

    如果 Python 3.6 成功编译,请将 export PYTHONHOME=/usr/local 添加到您的 .bashrc 文件中。或者编辑 sysconfig 文件的前缀和 exec_prefix,但前者是一个更简单的解决方案。

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 2013-01-10
      • 1970-01-01
      • 2013-10-18
      • 2022-08-18
      • 2020-09-27
      • 1970-01-01
      • 2019-12-18
      • 2019-10-06
      相关资源
      最近更新 更多