我从源代码编译并安装了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的共享对象库,如下所示:
如果我打印搜索路径公司名称:
$ 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
是什么意思,它的默认路径在哪里?在
如果Python3.6成功编译,请将
export PYTHONHOME=/usr/local
添加到.bashrc
文件中。或者在sysconfig文件中编辑前缀和exec_前缀,但前者是一个更简单的解决方案。在相关问题 更多 >
编程相关推荐