在python 3.6.1中找不到与平台相关的库<exec_prefix>

2024-06-17 12:37:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我从源代码编译并安装了python3.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)一般来说,我不需要set PYTHONHOME变量(我也不想设置它)。在

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

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

^{pr2}$

如果我打印搜索路径公司名称:

$ 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是什么意思,它的默认路径在哪里?在


Tags: librariesprefixlinuxlibusrnotmathfind
1条回答
网友
1楼 · 发布于 2024-06-17 12:37:22

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

相关问题 更多 >