ubuntu16.04 python2.7.12 报“ImportError: No module named site”错


安装完ubuntu16.04之后运行python出现此问题:

Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

解决前两条需要:

$ export PYTHONHOME=
制空pythonhome参数

解决第三条问题需要:

$ find / -name site.py*
#查找site模块的位置
#得到
/usr/src/Python-2.7.13/Lib/site.pyo
/usr/src/Python-2.7.13/Lib/site.pyc
/usr/src/Python-2.7.13/Lib/site.py
/usr/local/lib/python2.7/site.pyo
/usr/local/lib/python2.7/site.pyc
/usr/local/lib/python2.7/site.py
然后
$ export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python
问题解决

Python路径相关环境变量的意义。

PYTHONHOME:指定Python的标准库。
PYTHONPATH:用于扩充Python查找模块文件的路径。

转载自:https://blog.csdn.net/l6807718/article/details/61202140

You may also like...