Python 安装
Python 安装
(1) 准备编译环境
yum -y install gcc g++ gcc-c++ libstdc++-devel
yum -y install zlib-devel bzip2-devel ncurses-devel openssl openssl-devel
(2) 下载 Python3.5 代码包
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
(3) 编译安装
在安装包中有一个 README 的文件,里面有写如何安装
tar Jxvf Python-3.5.0.tar.xz
cd Python-3.5.0
./configure --prefix=/usr/local/lib/python3
make && make install
(4) 软链接
ln -s /usr/local/lib/python3 /usr/local/python
(4) 添加环境变量
在 /etc/profile.d 下新添加 python.sh 文件
vim /etc/profile.d/python.sh
PYTHON_HOME=/usr/local/python
export PATH=$PATH:$PYTHON_HOME/bin
export PYTHONPATH=$PYTHONPATH:$PYTHON_HOME/lib/python2.7
问题 1: fatal error: linux/limits.h: No such file or directory
yum install kernel-headers kernel-devel
In file included from /usr/include/x86_64-linux-gnu/bits/posix1_lim.h:160:0,
from /usr/include/limits.h:143,
from /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h:168,
from /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h:7,
from /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h:34,
from scripts/basic/fixdep.c:114:
/usr/include/bits/local_lim.h:38:26: fatal error: linux/limits.h: No such file or directory\
Linux 编译内核遇到找不到 linux/limits.h 的问题
问题 2: 设置了 Python 的路径,但启动 Python 时总是报 ImportError: No module named site 这个错误
[root@localhost zookeeper-3.4.6]# python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site
[root@localhost zookeeper-3.4.6]# cd /usr/local/lib/python27/
解决:
查看Python路径相关环境变量的意义。
- PYTHONHOME :指定 Python 的标准库。
- PYTHONPATH :用于扩充 Python 查找模块文件的路径。
这里是导入 site 模块时出错,所以应该在 PYTHONPATH 上增加 site 模块的路径。
查找site相关文件的路径:
[root@tZ etc]# find / -name site.py*
/usr/lib64/python2.7/site.pyc
/usr/lib64/python2.7/site.py
/usr/lib64/python2.7/site.pyo
增加路径到环境变量:
export PYTHONPATH=$PYTHONPATH:/usr/lib64/python2.7
posted on 2018-04-11 06:45 binarylei 阅读(6122) 评论(0) 编辑 收藏 举报